skip_log_in_screen.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/infrastructure/repos/user_repo.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 AuthRepository authRepo;
  24. const SkipLogInScreen({
  25. Key? key,
  26. required this.router,
  27. required this.authRepo,
  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. if (await canLaunch(url)) {
  85. await launch(url);
  86. } else {
  87. throw 'Could not launch $url';
  88. }
  89. }
  90. void _autoRegister(BuildContext context) async {
  91. const password = "AppFlowy123@";
  92. final uid = uuid();
  93. final userEmail = "[email protected]";
  94. final result = await widget.authRepo.signUp(
  95. name: LocaleKeys.defaultUsername.tr(),
  96. password: password,
  97. email: userEmail,
  98. );
  99. result.fold(
  100. (user) {
  101. FolderEventReadCurWorkspace().send().then((result) {
  102. _openCurrentWorkspace(context, user, result);
  103. });
  104. },
  105. (error) {
  106. Log.error(error);
  107. },
  108. );
  109. }
  110. void _openCurrentWorkspace(
  111. BuildContext context,
  112. UserProfile user,
  113. dartz.Either<CurrentWorkspaceSetting, FlowyError> workspacesOrError,
  114. ) {
  115. workspacesOrError.fold(
  116. (workspaceSetting) {
  117. widget.router.pushHomeScreen(context, user, workspaceSetting);
  118. },
  119. (error) {
  120. Log.error(error);
  121. },
  122. );
  123. }
  124. }
  125. class GoButton extends StatelessWidget {
  126. final VoidCallback onPressed;
  127. const GoButton({
  128. Key? key,
  129. required this.onPressed,
  130. }) : super(key: key);
  131. @override
  132. Widget build(BuildContext context) {
  133. final theme = context.watch<AppTheme>();
  134. return RoundedTextButton(
  135. title: LocaleKeys.letsGoButtonText.tr(),
  136. height: 50,
  137. borderRadius: Corners.s10Border,
  138. color: theme.main1,
  139. onPressed: onPressed,
  140. );
  141. }
  142. }