skip_log_in_screen.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import 'package:app_flowy/user/application/auth_service.dart';
  2. import 'package:app_flowy/user/presentation/router.dart';
  3. import 'package:app_flowy/user/presentation/widgets/background.dart';
  4. import 'package:easy_localization/easy_localization.dart';
  5. import 'package:flowy_infra/size.dart';
  6. import 'package:flowy_infra/uuid.dart';
  7. import 'package:flowy_infra_ui/style_widget/text.dart';
  8. import 'package:flowy_infra_ui/widget/rounded_button.dart';
  9. import 'package:flowy_infra_ui/widget/spacing.dart';
  10. import 'package:flowy_sdk/log.dart';
  11. import 'package:flowy_sdk/dispatch/dispatch.dart';
  12. import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart';
  13. import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
  14. import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
  15. import 'package:flutter/material.dart';
  16. import 'package:url_launcher/url_launcher.dart';
  17. import 'package:dartz/dartz.dart' as dartz;
  18. import 'package:app_flowy/generated/locale_keys.g.dart';
  19. class SkipLogInScreen extends StatefulWidget {
  20. final AuthRouter router;
  21. final AuthService authService;
  22. const SkipLogInScreen({
  23. Key? key,
  24. required this.router,
  25. required this.authService,
  26. }) : super(key: key);
  27. @override
  28. State<SkipLogInScreen> createState() => _SkipLogInScreenState();
  29. }
  30. class _SkipLogInScreenState extends State<SkipLogInScreen> {
  31. @override
  32. Widget build(BuildContext context) {
  33. return Scaffold(
  34. body: Center(
  35. child: SizedBox(
  36. width: 400,
  37. height: 600,
  38. child: _renderBody(context),
  39. ),
  40. ),
  41. );
  42. }
  43. Widget _renderBody(BuildContext context) {
  44. return Column(
  45. mainAxisAlignment: MainAxisAlignment.center,
  46. children: [
  47. FlowyLogoTitle(
  48. title: LocaleKeys.welcomeText.tr(),
  49. logoSize: const Size.square(60),
  50. ),
  51. const VSpace(80),
  52. GoButton(onPressed: () => _autoRegister(context)),
  53. const VSpace(30),
  54. Row(
  55. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  56. children: [
  57. InkWell(
  58. hoverColor: Colors.transparent,
  59. onTap: () =>
  60. _launchURL('https://github.com/AppFlowy-IO/appflowy'),
  61. child: FlowyText.medium(
  62. LocaleKeys.githubStarText.tr(),
  63. color: Theme.of(context).colorScheme.primary,
  64. decoration: TextDecoration.underline,
  65. ),
  66. ),
  67. InkWell(
  68. hoverColor: Colors.transparent,
  69. onTap: () => _launchURL('https://www.appflowy.io/blog'),
  70. child: FlowyText.medium(
  71. LocaleKeys.subscribeNewsletterText.tr(),
  72. color: Theme.of(context).colorScheme.primary,
  73. decoration: TextDecoration.underline,
  74. ),
  75. ),
  76. ],
  77. )
  78. ],
  79. );
  80. }
  81. _launchURL(String url) async {
  82. final uri = Uri.parse(url);
  83. if (await canLaunchUrl(uri)) {
  84. await launchUrl(uri);
  85. } else {
  86. throw 'Could not launch $url';
  87. }
  88. }
  89. void _autoRegister(BuildContext context) async {
  90. const password = "AppFlowy123@";
  91. final uid = uuid();
  92. final userEmail = "[email protected]";
  93. final result = await widget.authService.signUp(
  94. name: LocaleKeys.defaultUsername.tr(),
  95. password: password,
  96. email: userEmail,
  97. );
  98. result.fold(
  99. (user) {
  100. FolderEventReadCurrentWorkspace().send().then((result) {
  101. _openCurrentWorkspace(context, user, result);
  102. });
  103. },
  104. (error) {
  105. Log.error(error);
  106. },
  107. );
  108. }
  109. void _openCurrentWorkspace(
  110. BuildContext context,
  111. UserProfilePB user,
  112. dartz.Either<WorkspaceSettingPB, FlowyError> workspacesOrError,
  113. ) {
  114. workspacesOrError.fold(
  115. (workspaceSetting) {
  116. widget.router.pushHomeScreen(context, user, workspaceSetting);
  117. },
  118. (error) {
  119. Log.error(error);
  120. },
  121. );
  122. }
  123. }
  124. class GoButton extends StatelessWidget {
  125. final VoidCallback onPressed;
  126. const GoButton({
  127. Key? key,
  128. required this.onPressed,
  129. }) : super(key: key);
  130. @override
  131. Widget build(BuildContext context) {
  132. return RoundedTextButton(
  133. title: LocaleKeys.letsGoButtonText.tr(),
  134. fontSize: FontSizes.s16,
  135. height: 50,
  136. borderRadius: Corners.s10Border,
  137. onPressed: onPressed,
  138. );
  139. }
  140. }