81 lines
2.5 KiB
Dart
81 lines
2.5 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../features/onboarding/screens/onboarding_screen.dart';
|
|
import '../../features/tasks/providers/task_providers.dart';
|
|
import '../../features/tasks/screens/tasks_screen.dart';
|
|
import '../../features/tasks/screens/pet_screen.dart';
|
|
import '../../features/zen_mode/screens/zen_screen.dart';
|
|
import '../../shared/widgets/profile_screen.dart';
|
|
import '../../shared/widgets/app_shell.dart';
|
|
import 'routes.dart';
|
|
|
|
final appRouterProvider = Provider<GoRouter>((ref) {
|
|
final currentUser = ref.watch(currentUserProvider);
|
|
|
|
return GoRouter(
|
|
initialLocation: Routes.tasks,
|
|
redirect: (context, state) {
|
|
final isOnboarding = state.matchedLocation == Routes.onboarding;
|
|
|
|
// While loading user from DB, don't redirect
|
|
if (currentUser.isLoading) return null;
|
|
|
|
final hasUser = currentUser.value != null;
|
|
|
|
if (!hasUser && !isOnboarding) return Routes.onboarding;
|
|
if (hasUser && isOnboarding) return Routes.tasks;
|
|
return null;
|
|
},
|
|
routes: [
|
|
// Onboarding — outside shell, no bottom nav
|
|
GoRoute(
|
|
path: Routes.onboarding,
|
|
builder: (context, state) => const OnboardingScreen(),
|
|
),
|
|
StatefulShellRoute.indexedStack(
|
|
builder: (context, state, navigationShell) {
|
|
return AppShell(navigationShell: navigationShell);
|
|
},
|
|
branches: [
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: Routes.tasks,
|
|
pageBuilder: (context, state) => const NoTransitionPage(
|
|
child: TasksScreen(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: Routes.pet,
|
|
pageBuilder: (context, state) => const NoTransitionPage(
|
|
child: PetScreen(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: Routes.profile,
|
|
pageBuilder: (context, state) => const NoTransitionPage(
|
|
child: ProfileScreen(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
// Zen mode — outside shell, no bottom nav
|
|
GoRoute(
|
|
path: Routes.zen,
|
|
builder: (context, state) => const ZenScreen(),
|
|
),
|
|
],
|
|
);
|
|
});
|