skip_log_in_screen.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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-folder-data-model/protobuf.dart';
  13. import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
  14. import 'package:flutter/material.dart';
  15. import 'package:flutter_bloc/flutter_bloc.dart';
  16. import 'package:url_launcher/url_launcher.dart';
  17. import 'package:dartz/dartz.dart' as dartz;
  18. import 'package:app_flowy/generated/locale_keys.g.dart';
  19. class SkipLogInScreen extends StatefulWidget {
  20. final IAuthRouter router;
  21. final IAuth authManager;
  22. const SkipLogInScreen({
  23. Key? key,
  24. required this.router,
  25. required this.authManager,
  26. }) : super(key: key);
  27. @override
  28. State<SkipLogInScreen> createState() => _SkipLogInScreenState();
  29. }
  30. class _SkipLogInScreenState extends State<SkipLogInScreen> {
  31. IUserListener? userListener;
  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. if (await canLaunch(url)) {
  83. await launch(url);
  84. } else {
  85. throw 'Could not launch $url';
  86. }
  87. }
  88. void _autoRegister(BuildContext context) async {
  89. const password = "AppFlowy123@";
  90. final uid = uuid();
  91. final userEmail = "[email protected]";
  92. final result = await widget.authManager.signUp(LocaleKeys.defaultUsername.tr(), password, userEmail);
  93. result.fold(
  94. (user) {
  95. FolderEventReadCurWorkspace().send().then((result) {
  96. _openCurrentWorkspace(context, user, result);
  97. });
  98. },
  99. (error) {
  100. Log.error(error);
  101. },
  102. );
  103. }
  104. void _openCurrentWorkspace(
  105. BuildContext context,
  106. UserProfile user,
  107. dartz.Either<CurrentWorkspaceSetting, FlowyError> workspacesOrError,
  108. ) {
  109. workspacesOrError.fold(
  110. (workspaceSetting) {
  111. widget.router.pushHomeScreen(context, user, workspaceSetting);
  112. },
  113. (error) {
  114. Log.error(error);
  115. },
  116. );
  117. }
  118. }
  119. class GoButton extends StatelessWidget {
  120. final VoidCallback onPressed;
  121. const GoButton({
  122. Key? key,
  123. required this.onPressed,
  124. }) : super(key: key);
  125. @override
  126. Widget build(BuildContext context) {
  127. final theme = context.watch<AppTheme>();
  128. return RoundedTextButton(
  129. title: LocaleKeys.letsGoButtonText.tr(),
  130. height: 50,
  131. borderRadius: Corners.s10Border,
  132. color: theme.main1,
  133. onPressed: onPressed,
  134. );
  135. }
  136. }