skip_log_in_screen.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'package:app_flowy/startup/startup.dart';
  2. import 'package:app_flowy/user/domain/i_auth.dart';
  3. import 'package:app_flowy/user/presentation/widgets/background.dart';
  4. import 'package:app_flowy/workspace/domain/i_user.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:flutter/material.dart';
  12. import 'package:flutter_bloc/flutter_bloc.dart';
  13. import 'package:url_launcher/url_launcher.dart';
  14. class SkipLogInScreen extends StatefulWidget {
  15. final IAuthRouter router;
  16. final IAuth authManager;
  17. const SkipLogInScreen({
  18. Key? key,
  19. required this.router,
  20. required this.authManager,
  21. }) : super(key: key);
  22. @override
  23. State<SkipLogInScreen> createState() => _SkipLogInScreenState();
  24. }
  25. class _SkipLogInScreenState extends State<SkipLogInScreen> {
  26. IUserListener? userListener;
  27. @override
  28. Widget build(BuildContext context) {
  29. return Scaffold(
  30. body: Center(
  31. child: SizedBox(
  32. width: 400,
  33. height: 600,
  34. child: _renderBody(context),
  35. ),
  36. ),
  37. );
  38. }
  39. Widget _renderBody(BuildContext context) {
  40. return Column(
  41. mainAxisAlignment: MainAxisAlignment.center,
  42. children: [
  43. const FlowyLogoTitle(
  44. title: 'Welcome to AppFlowy',
  45. logoSize: Size.square(60),
  46. ),
  47. const VSpace(80),
  48. GoButton(onPressed: () => _autoRegister(context)),
  49. const VSpace(30),
  50. Row(
  51. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  52. children: [
  53. InkWell(
  54. child: const Text(
  55. 'Star on Github',
  56. style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  57. ),
  58. onTap: () {
  59. _launchURL('https://github.com/AppFlowy-IO/appflowy');
  60. },
  61. ),
  62. InkWell(
  63. child: const Text(
  64. 'Subscribe to Newsletter',
  65. style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  66. ),
  67. onTap: () {
  68. _launchURL('https://www.appflowy.io/blog');
  69. },
  70. ),
  71. ],
  72. )
  73. ],
  74. );
  75. }
  76. _launchURL(String url) async {
  77. if (await canLaunch(url)) {
  78. await launch(url);
  79. } else {
  80. throw 'Could not launch $url';
  81. }
  82. }
  83. void _autoRegister(BuildContext context) async {
  84. const password = "AppFlowy123@";
  85. final uid = uuid();
  86. final userEmail = "[email protected]";
  87. final result = await widget.authManager.signUp("FlowyUser", password, userEmail);
  88. result.fold(
  89. (user) {
  90. userListener = getIt<IUserListener>(param1: user);
  91. // router.pushHomeScreen(context, newUser.profile, newUser.workspaceId);
  92. },
  93. (error) {
  94. Log.error(error);
  95. },
  96. );
  97. }
  98. }
  99. class GoButton extends StatelessWidget {
  100. final VoidCallback onPressed;
  101. const GoButton({
  102. Key? key,
  103. required this.onPressed,
  104. }) : super(key: key);
  105. @override
  106. Widget build(BuildContext context) {
  107. final theme = context.watch<AppTheme>();
  108. return RoundedTextButton(
  109. title: 'Let\'s Go',
  110. height: 50,
  111. borderRadius: Corners.s10Border,
  112. color: theme.main1,
  113. onPressed: onPressed,
  114. );
  115. }
  116. }