router.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import 'package:appflowy/startup/startup.dart';
  2. import 'package:appflowy/user/application/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-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(
  28. BuildContext context,
  29. UserProfilePB profile,
  30. WorkspaceSettingPB workspaceSetting,
  31. ) {
  32. Navigator.push(
  33. context,
  34. PageRoutes.fade(
  35. () => HomeScreen(
  36. profile,
  37. workspaceSetting,
  38. key: ValueKey(profile.id),
  39. ),
  40. RouteDurations.slow.inMilliseconds * .001,
  41. ),
  42. );
  43. }
  44. }
  45. class SplashRoute {
  46. Future<void> pushWelcomeScreen(
  47. BuildContext context,
  48. UserProfilePB userProfile,
  49. ) async {
  50. final screen = WelcomeScreen(userProfile: userProfile);
  51. await Navigator.of(context).push(
  52. PageRoutes.fade(
  53. () => screen,
  54. RouteDurations.slow.inMilliseconds * .001,
  55. ),
  56. );
  57. FolderEventReadCurrentWorkspace().send().then((result) {
  58. result.fold(
  59. (workspaceSettingPB) =>
  60. pushHomeScreen(context, userProfile, workspaceSettingPB),
  61. (r) => null,
  62. );
  63. });
  64. }
  65. void pushHomeScreen(
  66. BuildContext context,
  67. UserProfilePB userProfile,
  68. WorkspaceSettingPB workspaceSetting,
  69. ) {
  70. Navigator.push(
  71. context,
  72. PageRoutes.fade(
  73. () => HomeScreen(
  74. userProfile,
  75. workspaceSetting,
  76. key: ValueKey(userProfile.id),
  77. ),
  78. RouteDurations.slow.inMilliseconds * .001,
  79. ),
  80. );
  81. }
  82. void pushSignInScreen(BuildContext context) {
  83. Navigator.push(
  84. context,
  85. PageRoutes.fade(
  86. () => SignInScreen(router: getIt<AuthRouter>()),
  87. RouteDurations.slow.inMilliseconds * .001,
  88. ),
  89. );
  90. }
  91. void pushSkipLoginScreen(BuildContext context) {
  92. Navigator.push(
  93. context,
  94. PageRoutes.fade(
  95. () => SkipLogInScreen(
  96. router: getIt<AuthRouter>(),
  97. authService: getIt<AuthService>(),
  98. ),
  99. RouteDurations.slow.inMilliseconds * .001,
  100. ),
  101. );
  102. }
  103. }