router.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import 'package:appflowy/startup/startup.dart';
  2. import 'package:appflowy/user/application/auth/auth_service.dart';
  3. import 'package:appflowy/user/presentation/sign_in_screen.dart';
  4. import 'package:appflowy/user/presentation/sign_up_screen.dart';
  5. import 'package:appflowy/user/presentation/skip_log_in_screen.dart';
  6. import 'package:appflowy/user/presentation/welcome_screen.dart';
  7. import 'package:appflowy/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-folder2/protobuf.dart';
  14. import 'package:flutter/material.dart';
  15. const routerNameRoot = '/';
  16. const routerNameSignUp = '/signUp';
  17. const routerNameSignIn = '/signIn';
  18. const routerNameSkipLogIn = '/skipLogIn';
  19. const routerNameWelcome = '/welcome';
  20. const routerNameHome = '/home';
  21. class AuthRouter {
  22. void pushForgetPasswordScreen(BuildContext context) {}
  23. void pushWelcomeScreen(BuildContext context, UserProfilePB userProfile) {
  24. getIt<SplashRoute>().pushWelcomeScreen(context, userProfile);
  25. }
  26. void pushSignUpScreen(BuildContext context) {
  27. Navigator.of(context).push(
  28. PageRoutes.fade(
  29. () => SignUpScreen(router: getIt<AuthRouter>()),
  30. const RouteSettings(name: routerNameSignUp),
  31. ),
  32. );
  33. }
  34. void pushHomeScreenWithWorkSpace(
  35. BuildContext context,
  36. UserProfilePB profile,
  37. WorkspaceSettingPB workspaceSetting,
  38. ) {
  39. Navigator.push(
  40. context,
  41. PageRoutes.fade(
  42. () => HomeScreen(
  43. profile,
  44. workspaceSetting,
  45. key: ValueKey(profile.id),
  46. ),
  47. const RouteSettings(name: routerNameHome),
  48. RouteDurations.slow.inMilliseconds * .001,
  49. ),
  50. );
  51. }
  52. Future<void> pushHomeScreen(
  53. BuildContext context,
  54. UserProfilePB userProfile,
  55. ) async {
  56. final result = await FolderEventGetCurrentWorkspace().send();
  57. result.fold(
  58. (workspaceSettingPB) => pushHomeScreenWithWorkSpace(
  59. context,
  60. userProfile,
  61. workspaceSettingPB,
  62. ),
  63. (r) => pushWelcomeScreen(context, userProfile),
  64. );
  65. }
  66. }
  67. class SplashRoute {
  68. Future<void> pushWelcomeScreen(
  69. BuildContext context,
  70. UserProfilePB userProfile,
  71. ) async {
  72. final screen = WelcomeScreen(userProfile: userProfile);
  73. await Navigator.of(context).push(
  74. PageRoutes.fade(
  75. () => screen,
  76. const RouteSettings(name: routerNameWelcome),
  77. RouteDurations.slow.inMilliseconds * .001,
  78. ),
  79. );
  80. FolderEventGetCurrentWorkspace().send().then((result) {
  81. result.fold(
  82. (workspaceSettingPB) =>
  83. pushHomeScreen(context, userProfile, workspaceSettingPB),
  84. (r) => null,
  85. );
  86. });
  87. }
  88. void pushHomeScreen(
  89. BuildContext context,
  90. UserProfilePB userProfile,
  91. WorkspaceSettingPB workspaceSetting,
  92. ) {
  93. Navigator.push(
  94. context,
  95. PageRoutes.fade(
  96. () => HomeScreen(
  97. userProfile,
  98. workspaceSetting,
  99. key: ValueKey(userProfile.id),
  100. ),
  101. const RouteSettings(name: routerNameWelcome),
  102. RouteDurations.slow.inMilliseconds * .001,
  103. ),
  104. );
  105. }
  106. void pushSignInScreen(BuildContext context) {
  107. Navigator.push(
  108. context,
  109. PageRoutes.fade(
  110. () => SignInScreen(router: getIt<AuthRouter>()),
  111. const RouteSettings(name: routerNameSignIn),
  112. RouteDurations.slow.inMilliseconds * .001,
  113. ),
  114. );
  115. }
  116. void pushSkipLoginScreen(BuildContext context) {
  117. Navigator.push(
  118. context,
  119. PageRoutes.fade(
  120. () => SkipLogInScreen(
  121. router: getIt<AuthRouter>(),
  122. authService: getIt<AuthService>(),
  123. ),
  124. const RouteSettings(name: routerNameSkipLogIn),
  125. RouteDurations.slow.inMilliseconds * .001,
  126. ),
  127. );
  128. }
  129. }