skip_log_in_screen.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import 'package:app_flowy/user/domain/i_auth.dart';
  2. import 'package:app_flowy/user/presentation/widgets/background.dart';
  3. import 'package:app_flowy/workspace/domain/i_user.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_log/flowy_log.dart';
  11. import 'package:flowy_sdk/dispatch/dispatch.dart';
  12. import 'package:flowy_sdk/protobuf/flowy-core-infra/protobuf.dart';
  13. import 'package:flowy_sdk/protobuf/flowy-core/errors.pb.dart';
  14. import 'package:flowy_sdk/protobuf/flowy-user-infra/protobuf.dart' show UserProfile;
  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 IAuthRouter router;
  22. final IAuth authManager;
  23. const SkipLogInScreen({
  24. Key? key,
  25. required this.router,
  26. required this.authManager,
  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.authManager.signUp(LocaleKeys.defaultUsername.tr(), password, userEmail);
  94. result.fold(
  95. (user) {
  96. WorkspaceEventReadCurWorkspace().send().then((result) {
  97. _openCurrentWorkspace(context, user, result);
  98. });
  99. },
  100. (error) {
  101. Log.error(error);
  102. },
  103. );
  104. }
  105. void _openCurrentWorkspace(
  106. BuildContext context,
  107. UserProfile user,
  108. dartz.Either<CurrentWorkspaceSetting, WorkspaceError> workspacesOrError,
  109. ) {
  110. workspacesOrError.fold(
  111. (workspaceSetting) {
  112. widget.router.pushHomeScreen(context, user, workspaceSetting);
  113. },
  114. (error) {
  115. Log.error(error);
  116. },
  117. );
  118. }
  119. }
  120. class GoButton extends StatelessWidget {
  121. final VoidCallback onPressed;
  122. const GoButton({
  123. Key? key,
  124. required this.onPressed,
  125. }) : super(key: key);
  126. @override
  127. Widget build(BuildContext context) {
  128. final theme = context.watch<AppTheme>();
  129. return RoundedTextButton(
  130. title: LocaleKeys.letsGoButtonText.tr(),
  131. height: 50,
  132. borderRadius: Corners.s10Border,
  133. color: theme.main1,
  134. onPressed: onPressed,
  135. );
  136. }
  137. }