From 3870eea8d4adc5c42f9c9e0e3ffc7095d3cfe48f Mon Sep 17 00:00:00 2001 From: Andrea Bizzotto Date: Mon, 18 Mar 2024 16:00:14 +0000 Subject: [PATCH] Cleanup GoRouter startup logic --- lib/src/routing/app_router.dart | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/src/routing/app_router.dart b/lib/src/routing/app_router.dart index bc225dd0..fa5c7a1b 100644 --- a/lib/src/routing/app_router.dart +++ b/lib/src/routing/app_router.dart @@ -50,11 +50,9 @@ GoRouter goRouter(GoRouterRef ref) { navigatorKey: _rootNavigatorKey, debugLogDiagnostics: true, redirect: (context, state) { - if (appStartupState.isLoading) { - return '/loading'; - } - if (appStartupState.hasError) { - return '/error'; + // If the app is still initializing, show the /startup route + if (appStartupState.isLoading || appStartupState.hasError) { + return '/startup'; } final onboardingRepository = ref.read(onboardingRepositoryProvider).requireValue; @@ -84,17 +82,12 @@ GoRouter goRouter(GoRouterRef ref) { refreshListenable: GoRouterRefreshStream(authRepository.authStateChanges()), routes: [ GoRoute( - path: '/loading', - pageBuilder: (context, state) => const NoTransitionPage( - child: AppStartupLoadingWidget(), - ), - ), - GoRoute( - path: '/error', + path: '/startup', pageBuilder: (context, state) => NoTransitionPage( - child: AppStartupErrorWidget( - message: 'App initialization failed', - onRetry: () => ref.invalidate(appStartupProvider), + child: AppStartupWidget( + // * This is just a placeholder + // * The loaded route will be managed by GoRouter on state change + onLoaded: (_) => const SizedBox.shrink(), ), ), ),