skip_log_in_screen.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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:flowy_infra/size.dart';
  5. import 'package:flowy_infra/theme.dart';
  6. import 'package:flowy_infra/uuid.dart';
  7. import 'package:flowy_infra_ui/widget/rounded_button.dart';
  8. import 'package:flowy_infra_ui/widget/spacing.dart';
  9. import 'package:flowy_log/flowy_log.dart';
  10. import 'package:flowy_sdk/dispatch/dispatch.dart';
  11. import 'package:flowy_sdk/protobuf/flowy-workspace-infra/protobuf.dart';
  12. import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
  13. import 'package:flutter/material.dart';
  14. import 'package:flutter_bloc/flutter_bloc.dart';
  15. import 'package:url_launcher/url_launcher.dart';
  16. import 'package:dartz/dartz.dart' as dartz;
  17. class SkipLogInScreen extends StatefulWidget {
  18. final IAuthRouter router;
  19. final IAuth authManager;
  20. const SkipLogInScreen({
  21. Key? key,
  22. required this.router,
  23. required this.authManager,
  24. }) : super(key: key);
  25. @override
  26. State<SkipLogInScreen> createState() => _SkipLogInScreenState();
  27. }
  28. class _SkipLogInScreenState extends State<SkipLogInScreen> {
  29. IUserListener? userListener;
  30. @override
  31. Widget build(BuildContext context) {
  32. return Scaffold(
  33. body: Center(
  34. child: SizedBox(
  35. width: 400,
  36. height: 600,
  37. child: _renderBody(context),
  38. ),
  39. ),
  40. );
  41. }
  42. Widget _renderBody(BuildContext context) {
  43. return Column(
  44. mainAxisAlignment: MainAxisAlignment.center,
  45. children: [
  46. const FlowyLogoTitle(
  47. title: 'Welcome to AppFlowy',
  48. logoSize: Size.square(60),
  49. ),
  50. const VSpace(80),
  51. GoButton(onPressed: () => _autoRegister(context)),
  52. const VSpace(30),
  53. Row(
  54. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  55. children: [
  56. InkWell(
  57. child: const Text(
  58. 'Star on Github',
  59. style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  60. ),
  61. onTap: () {
  62. _launchURL('https://github.com/AppFlowy-IO/appflowy');
  63. },
  64. ),
  65. InkWell(
  66. child: const Text(
  67. 'Subscribe to Newsletter',
  68. style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  69. ),
  70. onTap: () {
  71. _launchURL('https://www.appflowy.io/blog');
  72. },
  73. ),
  74. ],
  75. )
  76. ],
  77. );
  78. }
  79. _launchURL(String url) async {
  80. if (await canLaunch(url)) {
  81. await launch(url);
  82. } else {
  83. throw 'Could not launch $url';
  84. }
  85. }
  86. void _autoRegister(BuildContext context) async {
  87. const password = "AppFlowy123@";
  88. final uid = uuid();
  89. final userEmail = "[email protected]";
  90. final result = await widget.authManager.signUp("Me", password, userEmail);
  91. result.fold(
  92. (user) {
  93. WorkspaceEventReadCurWorkspace().send().then((result) {
  94. _openCurrentWorkspace(context, user, result);
  95. });
  96. },
  97. (error) {
  98. Log.error(error);
  99. },
  100. );
  101. }
  102. void _openCurrentWorkspace(
  103. BuildContext context,
  104. UserProfile user,
  105. dartz.Either<CurrentWorkspaceSetting, WorkspaceError> workspacesOrError,
  106. ) {
  107. workspacesOrError.fold(
  108. (workspaceSetting) {
  109. widget.router.pushHomeScreen(context, user, workspaceSetting);
  110. },
  111. (error) {
  112. Log.error(error);
  113. },
  114. );
  115. }
  116. }
  117. class GoButton extends StatelessWidget {
  118. final VoidCallback onPressed;
  119. const GoButton({
  120. Key? key,
  121. required this.onPressed,
  122. }) : super(key: key);
  123. @override
  124. Widget build(BuildContext context) {
  125. final theme = context.watch<AppTheme>();
  126. return RoundedTextButton(
  127. title: 'Let\'s Go',
  128. height: 50,
  129. borderRadius: Corners.s10Border,
  130. color: theme.main1,
  131. onPressed: onPressed,
  132. );
  133. }
  134. }