import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import '../screens/auth_screens.dart'; import '../screens/availability_screen.dart'; import '../screens/clock_screen.dart'; import '../screens/compliance_screens.dart'; import '../screens/home_shell.dart'; import '../screens/onboarding_screens.dart'; import '../screens/pay_screens.dart'; import '../screens/profile_detail_screens.dart'; import '../screens/profile_screen.dart'; import '../screens/requirements_screen.dart'; import '../screens/settings_screens.dart'; import '../screens/shift_detail_screen.dart'; import '../screens/shifts_screen.dart'; import '../screens/timecard_screens.dart'; import '../screens/today_screen.dart'; import '../state/compliance_controller.dart'; import 'transitions.dart'; final _rootKey = GlobalKey(); ComplianceSection _sectionFromName(String name) => ComplianceSection.values.firstWhere( (s) => s.name == name, orElse: () => ComplianceSection.documents, ); /// A screen that replaces what came before it. GoRoute _fadeRoute(String path, Widget Function() build) => GoRoute( path: path, pageBuilder: (_, state) => Transitions.fade(state, build()), ); /// A screen pushed on top of the shell. GoRoute _detailRoute( String path, Widget Function(GoRouterState) build, { List routes = const [], }) => GoRoute( path: path, parentNavigatorKey: _rootKey, pageBuilder: (_, state) => Transitions.push(state, build(state)), routes: routes, ); /// Sign-in lives outside the shell; the five tabs each keep their own stack, /// and detail screens push over the whole shell. final router = GoRouter( navigatorKey: _rootKey, initialLocation: '/', routes: [ _fadeRoute('/', SplashScreen.new), _fadeRoute('/onboarding', OnboardingScreen.new), _fadeRoute('/welcome', WelcomeScreen.new), _fadeRoute('/verified', VerifiedScreen.new), _fadeRoute('/permissions', PermissionsScreen.new), // The two sign-in steps are pushed, so back gestures read correctly. _detailRoute('/phone', (_) => const PhoneScreen()), _detailRoute('/otp', (_) => const OtpScreen()), // Branch order is the tab order, and it matches the prototype: Today sits // in the middle, with the two browsing tabs to its left and the two // personal ones to its right. KrowNavBar's items must stay in step. StatefulShellRoute.indexedStack( builder: (_, _, shell) => HomeShell(navigationShell: shell), branches: [ StatefulShellBranch( routes: [ GoRoute(path: '/shifts', builder: (_, _) => const ShiftsScreen()), ], ), StatefulShellBranch( routes: [GoRoute(path: '/pay', builder: (_, _) => const PayScreen())], ), StatefulShellBranch( routes: [ GoRoute(path: '/today', builder: (_, _) => const TodayScreen()), ], ), StatefulShellBranch( routes: [ GoRoute(path: '/clock', builder: (_, _) => const ClockScreen()), ], ), StatefulShellBranch( routes: [ GoRoute(path: '/profile', builder: (_, _) => const ProfileScreen()), ], ), ], ), _detailRoute( '/shift/:id', (state) => ShiftDetailScreen(shiftId: state.pathParameters['id']!), routes: [ _detailRoute( 'requirements', (state) => RequirementsScreen(shiftId: state.pathParameters['id']!), ), ], ), _detailRoute('/availability', (_) => const AvailabilityScreen()), _detailRoute('/timecards', (_) => const TimecardsScreen()), _detailRoute( '/timecard/:id', (state) => TimecardReviewScreen(timecardId: state.pathParameters['id']!), ), _detailRoute('/payroll', (_) => const PayrollScheduleScreen()), _detailRoute( '/payment/:id', (state) => PaymentDetailScreen(shiftId: state.pathParameters['id']!), ), _detailRoute( '/compliance', (_) => const ComplianceHubScreen(), routes: [ _detailRoute( ':section', (state) => ComplianceListScreen( section: _sectionFromName(state.pathParameters['section']!), ), routes: [ _detailRoute( ':itemId', (state) => ComplianceDetailScreen( section: _sectionFromName(state.pathParameters['section']!), itemId: state.pathParameters['itemId']!, ), ), ], ), ], ), _detailRoute('/emergency-contacts', (_) => const EmergencyContactsScreen()), _detailRoute('/skills', (_) => const SkillsScreen()), _detailRoute('/direct-deposit', (_) => const DirectDepositScreen()), _detailRoute('/benefits', (_) => const BenefitsScreen()), _detailRoute('/settings', (_) => const SettingsScreen()), _detailRoute('/support', (_) => const SupportScreen()), _detailRoute('/faqs', (_) => const FaqScreen()), _detailRoute('/privacy', (_) => const PrivacyScreen()), ], );