skip_log_in_screen.dart 4.7 KB

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