welcome_screen.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import 'package:app_flowy/welcome/domain/i_welcome.dart';
  2. import 'package:app_flowy/welcome/domain/auth_state.dart';
  3. import 'package:app_flowy/startup/startup.dart';
  4. import 'package:app_flowy/welcome/application/welcome_bloc.dart';
  5. import 'package:flowy_infra_ui/widget/route/animation.dart';
  6. import 'package:flowy_infra/flowy_logger.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_bloc/flutter_bloc.dart';
  9. import 'package:flowy_infra/time/prelude.dart';
  10. class WelcomeScreen extends StatelessWidget {
  11. const WelcomeScreen({Key? key}) : super(key: key);
  12. @override
  13. Widget build(BuildContext context) {
  14. return BlocProvider(
  15. create: (context) {
  16. return getIt<WelcomeBloc>()..add(const WelcomeEvent.getUser());
  17. },
  18. child: Scaffold(
  19. body: BlocListener<WelcomeBloc, WelcomeState>(
  20. listener: (context, state) {
  21. state.auth.map(
  22. authenticated: (r) => _handleAuthenticated(context, r),
  23. unauthenticated: (r) => _handleUnauthenticated(context, r),
  24. initial: (r) => {},
  25. );
  26. },
  27. child: const Body(),
  28. ),
  29. ),
  30. );
  31. }
  32. void _pushToScreen(BuildContext context, Widget screen) {
  33. /// Let the splash view sit for a bit. Mainly for aesthetics and to ensure a smooth intro animation.
  34. Navigator.push(
  35. context,
  36. PageRoutes.fade(
  37. () => screen, RouteDurations.slow.inMilliseconds * .001));
  38. }
  39. void _handleAuthenticated(BuildContext context, Authenticated result) {
  40. getIt<IWelcomeRoute>().pushHomeScreen(context, result.userProfile);
  41. }
  42. void _handleUnauthenticated(BuildContext context, Unauthenticated result) {
  43. Log.error(result.error);
  44. _pushToScreen(context, getIt<IWelcomeRoute>().pushSignInScreen());
  45. }
  46. }
  47. class Body extends StatelessWidget {
  48. const Body({Key? key}) : super(key: key);
  49. @override
  50. Widget build(BuildContext context) {
  51. var size = MediaQuery.of(context).size;
  52. return Container(
  53. alignment: Alignment.center,
  54. child: SingleChildScrollView(
  55. child: Stack(
  56. alignment: Alignment.center,
  57. children: [
  58. Image(
  59. fit: BoxFit.cover,
  60. width: size.width,
  61. height: size.height,
  62. image: const AssetImage(
  63. 'assets/images/appflowy_launch_splash.jpg')),
  64. const CircularProgressIndicator.adaptive(),
  65. ],
  66. ),
  67. ),
  68. );
  69. }
  70. }