skip_log_in_screen.dart 3.1 KB

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