skip_log_in_screen.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import 'package:app_flowy/user/infrastructure/router.dart';
  2. import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
  3. import 'package:app_flowy/user/presentation/widgets/background.dart';
  4. import 'package:app_flowy/workspace/domain/i_user.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_log/flowy_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: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 AuthRepository authRepo;
  23. const SkipLogInScreen({
  24. Key? key,
  25. required this.router,
  26. required this.authRepo,
  27. }) : super(key: key);
  28. @override
  29. State<SkipLogInScreen> createState() => _SkipLogInScreenState();
  30. }
  31. class _SkipLogInScreenState extends State<SkipLogInScreen> {
  32. IUserListener? userListener;
  33. @override
  34. Widget build(BuildContext context) {
  35. return Scaffold(
  36. body: Center(
  37. child: SizedBox(
  38. width: 400,
  39. height: 600,
  40. child: _renderBody(context),
  41. ),
  42. ),
  43. );
  44. }
  45. Widget _renderBody(BuildContext context) {
  46. return Column(
  47. mainAxisAlignment: MainAxisAlignment.center,
  48. children: [
  49. FlowyLogoTitle(
  50. title: LocaleKeys.welcomeText.tr(),
  51. logoSize: const Size.square(60),
  52. ),
  53. const VSpace(80),
  54. GoButton(onPressed: () => _autoRegister(context)),
  55. const VSpace(30),
  56. Row(
  57. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  58. children: [
  59. InkWell(
  60. child: Text(
  61. LocaleKeys.githubStarText.tr(),
  62. style: const TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  63. ),
  64. onTap: () {
  65. _launchURL('https://github.com/AppFlowy-IO/appflowy');
  66. },
  67. ),
  68. InkWell(
  69. child: Text(
  70. LocaleKeys.subscribeNewsletterText.tr(),
  71. style: const TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  72. ),
  73. onTap: () {
  74. _launchURL('https://www.appflowy.io/blog');
  75. },
  76. ),
  77. ],
  78. )
  79. ],
  80. );
  81. }
  82. _launchURL(String url) async {
  83. if (await canLaunch(url)) {
  84. await launch(url);
  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.authRepo.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. UserProfile user,
  112. dartz.Either<CurrentWorkspaceSetting, 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. }