Skip to content

Commit

Permalink
Cleanup GoRouter startup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bizz84 committed Mar 18, 2024
1 parent 1a7feae commit 3870eea
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/src/routing/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
),
),
),
Expand Down

0 comments on commit 3870eea

Please sign in to comment.