skip_log_in_screen.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // ignore_for_file: prefer_const_constructors
  2. import 'package:app_flowy/startup/startup.dart';
  3. import 'package:app_flowy/user/application/sign_in_bloc.dart';
  4. import 'package:app_flowy/user/domain/i_auth.dart';
  5. import 'package:app_flowy/user/presentation/widgets/background.dart';
  6. import 'package:flowy_infra/size.dart';
  7. import 'package:flowy_infra/theme.dart';
  8. import 'package:flowy_infra_ui/widget/rounded_button.dart';
  9. import 'package:flowy_infra_ui/widget/spacing.dart';
  10. import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
  11. import 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart';
  12. import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
  13. import 'package:flutter/material.dart';
  14. import 'package:flutter_bloc/flutter_bloc.dart';
  15. import 'package:dartz/dartz.dart';
  16. import 'package:url_launcher/url_launcher.dart';
  17. class SkipLogInScreen extends StatelessWidget {
  18. final IAuthRouter router;
  19. const SkipLogInScreen({Key? key, required this.router}) : super(key: key);
  20. @override
  21. Widget build(BuildContext context) {
  22. return BlocProvider(
  23. create: (context) => getIt<SignInBloc>(),
  24. child: BlocListener<SignInBloc, SignInState>(
  25. listener: (context, state) {
  26. state.successOrFail.fold(
  27. () => null,
  28. (result) => _handleSuccessOrFail(result, context),
  29. );
  30. },
  31. child: Scaffold(
  32. body: SignInForm(router: router),
  33. ),
  34. ),
  35. );
  36. }
  37. void _handleSuccessOrFail(Either<UserProfile, UserError> result, BuildContext context) {
  38. result.fold(
  39. (user) => router.pushWelcomeScreen(context, user),
  40. (error) => showSnapBar(context, error.msg),
  41. );
  42. }
  43. }
  44. class SignInForm extends StatelessWidget {
  45. final IAuthRouter router;
  46. const SignInForm({
  47. Key? key,
  48. required this.router,
  49. }) : super(key: key);
  50. @override
  51. Widget build(BuildContext context) {
  52. return Center(
  53. child: SizedBox(
  54. width: 600,
  55. height: 600,
  56. child: Expanded(
  57. child: Column(
  58. // ignore: prefer_const_literals_to_create_immutables
  59. children: [
  60. const AuthFormTitle(
  61. title: 'Welcome to AppFlowy',
  62. logoSize: Size(60, 60),
  63. ),
  64. const VSpace(80),
  65. const GoButton(),
  66. const VSpace(30),
  67. Row(
  68. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  69. children: [
  70. // ignore: prefer_const_constructors
  71. InkWell(
  72. child: Text(
  73. 'Star on Github',
  74. style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  75. ),
  76. onTap: () {
  77. _launchURL('https://github.com/AppFlowy-IO/appflowy');
  78. },
  79. ),
  80. HSpace(60),
  81. InkWell(
  82. child: Text(
  83. 'Subscribe to Newsletter',
  84. style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
  85. ),
  86. onTap: () {
  87. _launchURL('https://www.appflowy.io/blog');
  88. }),
  89. ],
  90. )
  91. ],
  92. ),
  93. ),
  94. ),
  95. );
  96. }
  97. _launchURL(String url) async {
  98. if (await canLaunch(url)) {
  99. await launch(url);
  100. } else {
  101. throw 'Could not launch $url';
  102. }
  103. }
  104. }
  105. class GoButton extends StatelessWidget {
  106. const GoButton({
  107. Key? key,
  108. }) : super(key: key);
  109. @override
  110. Widget build(BuildContext context) {
  111. final theme = context.watch<AppTheme>();
  112. return RoundedTextButton(
  113. title: 'Let\'s Go',
  114. height: 60,
  115. borderRadius: Corners.s10Border,
  116. color: theme.main1,
  117. onPressed: () {
  118. //to do: direct to the workspace
  119. },
  120. );
  121. }
  122. }