router.dart 4.4 KB

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