skip_log_in_screen.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/theme.dart';
  7. import 'package:flowy_infra/uuid.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:flutter_bloc/flutter_bloc.dart';
  17. import 'package:url_launcher/url_launcher.dart';
  18. import 'package:dartz/dartz.dart' as dartz;
  19. import 'package:app_flowy/generated/locale_keys.g.dart';
  20. class SkipLogInScreen extends StatefulWidget {
  21. final AuthRouter router;
  22. final AuthService authService;
  23. const SkipLogInScreen({
  24. Key? key,
  25. required this.router,
  26. required this.authService,
  27. }) : super(key: key);
  28. @override
  29. State<SkipLogInScreen> createState() => _SkipLogInScreenState();
  30. }
  31. class _SkipLogInScreenState extends State<SkipLogInScreen> {
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. body: Center(
  36. child: SizedBox(
  37. width: 400,
  38. height: 600,
  39. child: _renderBody(context),
  40. ),
  41. ),
  42. );
  43. }
  44. Widget _renderBody(BuildContext context) {
  45. return Column(
  46. mainAxisAlignment: MainAxisAlignment.center,
  47. children: [
  48. FlowyLogoTitle(
  49. title: LocaleKeys.welcomeText.tr(),
  50. logoSize: const Size.square(60),
  51. ),
  52. const VSpace(80),
  53. GoButton(onPressed: () => _autoRegister(context)),
  54. const VSpace(30),
  55. Row(
  56. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  57. children: [
  58. InkWell(
  59. child: Text(
  60. LocaleKeys.githubStarText.tr(),
  61. style: const TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  62. ),
  63. onTap: () {
  64. _launchURL('https://github.com/AppFlowy-IO/appflowy');
  65. },
  66. ),
  67. InkWell(
  68. child: Text(
  69. LocaleKeys.subscribeNewsletterText.tr(),
  70. style: const TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  71. ),
  72. onTap: () {
  73. _launchURL('https://www.appflowy.io/blog');
  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. FolderEventReadCurWorkspace().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<CurrentWorkspaceSettingPB, 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. final theme = context.watch<AppTheme>();
  133. return RoundedTextButton(
  134. title: LocaleKeys.letsGoButtonText.tr(),
  135. height: 50,
  136. borderRadius: Corners.s10Border,
  137. color: theme.main1,
  138. onPressed: onPressed,
  139. );
  140. }
  141. }