router.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import 'package:app_flowy/startup/startup.dart';
  2. import 'package:app_flowy/user/application/auth_service.dart';
  3. import 'package:app_flowy/user/presentation/sign_in_screen.dart';
  4. import 'package:app_flowy/user/presentation/sign_up_screen.dart';
  5. import 'package:app_flowy/user/presentation/skip_log_in_screen.dart';
  6. import 'package:app_flowy/user/presentation/welcome_screen.dart';
  7. import 'package:app_flowy/workspace/presentation/home/home_screen.dart';
  8. import 'package:appflowy_backend/dispatch/dispatch.dart';
  9. import 'package:flowy_infra/time/duration.dart';
  10. import 'package:flowy_infra_ui/widget/route/animation.dart';
  11. import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
  12. show UserProfilePB;
  13. import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
  14. import 'package:flutter/material.dart';
  15. class AuthRouter {
  16. void pushForgetPasswordScreen(BuildContext context) {}
  17. void pushWelcomeScreen(BuildContext context, UserProfilePB userProfile) {
  18. getIt<SplashRoute>().pushWelcomeScreen(context, userProfile);
  19. }
  20. void pushSignUpScreen(BuildContext context) {
  21. Navigator.of(context).push(
  22. PageRoutes.fade(
  23. () => SignUpScreen(router: getIt<AuthRouter>()),
  24. ),
  25. );
  26. }
  27. void pushHomeScreen(BuildContext context, UserProfilePB profile,
  28. WorkspaceSettingPB workspaceSetting) {
  29. Navigator.push(
  30. context,
  31. PageRoutes.fade(
  32. () => HomeScreen(
  33. profile,
  34. workspaceSetting,
  35. key: ValueKey(profile.id),
  36. ),
  37. RouteDurations.slow.inMilliseconds * .001),
  38. );
  39. }
  40. }
  41. class SplashRoute {
  42. Future<void> pushWelcomeScreen(
  43. BuildContext context,
  44. UserProfilePB userProfile,
  45. ) async {
  46. final screen = WelcomeScreen(userProfile: userProfile);
  47. await Navigator.of(context).push(
  48. PageRoutes.fade(
  49. () => screen,
  50. RouteDurations.slow.inMilliseconds * .001,
  51. ),
  52. );
  53. FolderEventReadCurrentWorkspace().send().then((result) {
  54. result.fold(
  55. (workspaceSettingPB) =>
  56. pushHomeScreen(context, userProfile, workspaceSettingPB),
  57. (r) => null,
  58. );
  59. });
  60. }
  61. void pushHomeScreen(
  62. BuildContext context,
  63. UserProfilePB userProfile,
  64. WorkspaceSettingPB workspaceSetting,
  65. ) {
  66. Navigator.push(
  67. context,
  68. PageRoutes.fade(
  69. () => HomeScreen(
  70. userProfile,
  71. workspaceSetting,
  72. key: ValueKey(userProfile.id),
  73. ),
  74. RouteDurations.slow.inMilliseconds * .001),
  75. );
  76. }
  77. void pushSignInScreen(BuildContext context) {
  78. Navigator.push(
  79. context,
  80. PageRoutes.fade(() => SignInScreen(router: getIt<AuthRouter>()),
  81. RouteDurations.slow.inMilliseconds * .001),
  82. );
  83. }
  84. void pushSkipLoginScreen(BuildContext context) {
  85. Navigator.push(
  86. context,
  87. PageRoutes.fade(
  88. () => SkipLogInScreen(
  89. router: getIt<AuthRouter>(),
  90. authService: getIt<AuthService>(),
  91. ),
  92. RouteDurations.slow.inMilliseconds * .001),
  93. );
  94. }
  95. }