router.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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:flowy_infra/time/duration.dart';
  9. import 'package:flowy_infra_ui/widget/route/animation.dart';
  10. import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
  11. import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart';
  12. import 'package:flutter/material.dart';
  13. class AuthRouter {
  14. void pushForgetPasswordScreen(BuildContext context) {}
  15. void pushWelcomeScreen(BuildContext context, UserProfilePB userProfile) {
  16. getIt<SplashRoute>().pushWelcomeScreen(context, userProfile);
  17. }
  18. void pushSignUpScreen(BuildContext context) {
  19. Navigator.of(context).push(
  20. PageRoutes.fade(
  21. () => SignUpScreen(router: getIt<AuthRouter>()),
  22. ),
  23. );
  24. }
  25. void pushHomeScreen(BuildContext context, UserProfilePB profile,
  26. WorkspaceSettingPB workspaceSetting) {
  27. Navigator.push(
  28. context,
  29. PageRoutes.fade(
  30. () => HomeScreen(
  31. profile,
  32. workspaceSetting,
  33. key: ValueKey(profile.id),
  34. ),
  35. RouteDurations.slow.inMilliseconds * .001),
  36. );
  37. }
  38. }
  39. class SplashRoute {
  40. Future<void> pushWelcomeScreen(
  41. BuildContext context, UserProfilePB userProfile) async {
  42. final screen = WelcomeScreen(userProfile: userProfile);
  43. final workspaceId = await Navigator.of(context).push(
  44. PageRoutes.fade(
  45. () => screen,
  46. RouteDurations.slow.inMilliseconds * .001,
  47. ),
  48. );
  49. // ignore: use_build_context_synchronously
  50. pushHomeScreen(context, userProfile, workspaceId);
  51. }
  52. void pushHomeScreen(BuildContext context, UserProfilePB userProfile,
  53. WorkspaceSettingPB workspaceSetting) {
  54. Navigator.push(
  55. context,
  56. PageRoutes.fade(
  57. () => HomeScreen(
  58. userProfile,
  59. workspaceSetting,
  60. key: ValueKey(userProfile.id),
  61. ),
  62. RouteDurations.slow.inMilliseconds * .001),
  63. );
  64. }
  65. void pushSignInScreen(BuildContext context) {
  66. Navigator.push(
  67. context,
  68. PageRoutes.fade(() => SignInScreen(router: getIt<AuthRouter>()),
  69. RouteDurations.slow.inMilliseconds * .001),
  70. );
  71. }
  72. void pushSkipLoginScreen(BuildContext context) {
  73. Navigator.push(
  74. context,
  75. PageRoutes.fade(
  76. () => SkipLogInScreen(
  77. router: getIt<AuthRouter>(),
  78. authService: getIt<AuthService>(),
  79. ),
  80. RouteDurations.slow.inMilliseconds * .001),
  81. );
  82. }
  83. }