skip_log_in_screen.dart 4.0 KB

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