123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import 'package:appflowy/mobile/presentation/home/mobile_home_page.dart';
- import 'package:appflowy/startup/startup.dart';
- import 'package:appflowy/user/presentation/screens/screens.dart';
- import 'package:appflowy/workspace/presentation/home/desktop_home_screen.dart';
- import 'package:appflowy_backend/dispatch/dispatch.dart';
- import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
- import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
- show UserProfilePB;
- import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
- import 'package:flutter/material.dart';
- import 'package:appflowy/util/platform_extension.dart';
- import 'package:go_router/go_router.dart';
- class AuthRouter {
- void pushForgetPasswordScreen(BuildContext context) {}
- void pushWorkspaceStartScreen(
- BuildContext context,
- UserProfilePB userProfile,
- ) {
- getIt<SplashRouter>().pushWorkspaceStartScreen(context, userProfile);
- }
- void pushSignUpScreen(BuildContext context) {
- context.push(SignUpScreen.routeName);
- }
- /// Navigates to the home screen based on the current workspace and platform.
- ///
- /// This function takes in a [BuildContext] and a [UserProfilePB] object to
- /// determine the user's settings and then navigate to the appropriate home screen
- /// (`MobileHomeScreen` for mobile platforms, `DesktopHomeScreen` for others).
- ///
- /// It first fetches the current workspace settings using [FolderEventGetCurrentWorkspace].
- /// If the workspace settings are successfully fetched, it navigates to the home screen.
- /// If there's an error, it defaults to the workspace start screen.
- ///
- /// @param [context] BuildContext for navigating to the appropriate screen.
- /// @param [userProfile] UserProfilePB object containing the details of the current user.
- ///
- Future<void> goHomeScreen(
- BuildContext context,
- UserProfilePB userProfile,
- ) async {
- final result = await FolderEventGetCurrentWorkspace().send();
- result.fold(
- (workspaceSetting) {
- // Replace SignInScreen or SkipLogInScreen as root page.
- // If user click back button, it will exit app rather than go back to SignInScreen or SkipLogInScreen
- if (PlatformExtension.isMobile) {
- context.go(
- MobileHomeScreen.routeName,
- );
- } else {
- context.go(
- DesktopHomeScreen.routeName,
- );
- }
- },
- (error) => pushWorkspaceStartScreen(context, userProfile),
- );
- }
- Future<void> pushEncryptionScreen(
- BuildContext context,
- UserProfilePB userProfile,
- ) async {
- // After log in,push EncryptionScreen on the top SignInScreen
- context.push(
- EncryptSecretScreen.routeName,
- extra: {
- EncryptSecretScreen.argUser: userProfile,
- EncryptSecretScreen.argKey: ValueKey(userProfile.id),
- },
- );
- }
- Future<void> pushWorkspaceErrorScreen(
- BuildContext context,
- UserFolderPB userFolder,
- FlowyError error,
- ) async {
- await context.push(
- WorkspaceErrorScreen.routeName,
- extra: {
- WorkspaceErrorScreen.argUserFolder: userFolder,
- WorkspaceErrorScreen.argError: error,
- },
- );
- }
- }
- class SplashRouter {
- // Unused for now, it was planed to be used in SignUpScreen.
- // To let user choose workspace than navigate to corresponding home screen.
- Future<void> pushWorkspaceStartScreen(
- BuildContext context,
- UserProfilePB userProfile,
- ) async {
- await context.push(
- WorkspaceStartScreen.routeName,
- extra: {
- WorkspaceStartScreen.argUserProfile: userProfile,
- },
- );
- FolderEventGetCurrentWorkspace().send().then((result) {
- result.fold(
- (workspaceSettingPB) => pushHomeScreen(context),
- (r) => null,
- );
- });
- }
- void pushHomeScreen(
- BuildContext context,
- ) {
- if (PlatformExtension.isMobile) {
- context.push(
- MobileHomeScreen.routeName,
- );
- } else {
- context.push(
- DesktopHomeScreen.routeName,
- );
- }
- }
- void goHomeScreen(
- BuildContext context,
- ) {
- if (PlatformExtension.isMobile) {
- context.go(
- MobileHomeScreen.routeName,
- );
- } else {
- context.go(
- DesktopHomeScreen.routeName,
- );
- }
- }
- }
|