skip_log_in_screen.dart 4.4 KB

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