2026-05-07 10:22:06 +07:00

110 lines
5.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'core/storage/secure_storage.dart';
import 'core/constants/app_constants.dart';
import 'injection_container.dart';
// Auth
import 'features/server_connect/presentation/screens/server_connect_screen.dart';
import 'features/auth/presentation/screens/splash_screen.dart';
import 'features/auth/presentation/screens/login_screen.dart';
import 'features/auth/presentation/screens/register_screen.dart';
// User shell + screens
import 'shared/widgets/user_shell.dart';
import 'features/walk_guide/presentation/screens/walk_guide_screen.dart';
import 'features/sos/presentation/screens/sos_screen.dart';
import 'features/activity_log/presentation/screens/activity_log_screen.dart';
import 'features/notifications/presentation/screens/notification_screen.dart';
import 'features/navigation_mode/presentation/screens/navigation_mode_screen.dart';
import 'features/settings/presentation/screens/user_settings_screen.dart';
// Guardian shell + screens
import 'shared/widgets/guardian_shell.dart';
import 'features/guardian/presentation/screens/guardian_dashboard_screen.dart';
import 'features/guardian/presentation/screens/guardian_map_screen.dart';
import 'features/guardian/presentation/screens/guardian_activity_log_screen.dart';
import 'features/guardian/presentation/screens/guardian_send_notif_screen.dart';
import 'features/guardian/presentation/screens/guardian_ai_config_screen.dart';
import 'features/guardian/presentation/screens/guardian_voice_cmd_screen.dart';
import 'features/guardian/presentation/screens/guardian_shortcut_screen.dart';
import 'features/guardian/presentation/screens/guardian_geofence_screen.dart';
import 'features/pairing/presentation/screens/guardian_pairing_screen.dart';
import 'features/pairing/presentation/screens/user_pairing_screen.dart';
// Call
import 'features/call/presentation/screens/call_screen.dart';
import 'features/call/presentation/screens/incoming_call_screen.dart';
final GoRouter appRouter = GoRouter(
initialLocation: '/splash',
redirect: (context, state) async {
final serverUrl = await AppConstants.getServerUrl();
final path = state.matchedLocation;
// 1. No server URL → must go to server-connect
if (serverUrl == null || serverUrl.isEmpty) {
if (path != '/server-connect') return '/server-connect';
return null;
}
// 2. Already on server-connect but has URL → splash
if (path == '/server-connect') return '/splash';
return null;
},
routes: [
GoRoute(
path: '/server-connect',
builder: (context, state) => const ServerConnectScreen(),
),
GoRoute(
path: '/splash',
builder: (context, state) => const SplashScreen(),
),
GoRoute(
path: '/login',
builder: (context, state) => const LoginScreen(),
),
GoRoute(
path: '/register',
builder: (context, state) => const RegisterScreen(),
),
GoRoute(
path: '/incoming-call',
builder: (context, state) => const IncomingCallScreen(),
),
// ── USER SHELL ──────────────────────────────────────────────────────────
ShellRoute(
builder: (context, state, child) => UserShell(child: child),
routes: [
GoRoute(path: '/user/walkguide', builder: (c, s) => const WalkGuideScreen()),
GoRoute(path: '/user/sos', builder: (c, s) => const SosScreen()),
GoRoute(path: '/user/activity', builder: (c, s) => const ActivityLogScreen()),
GoRoute(path: '/user/notifications',builder: (c, s) => const NotificationScreen()),
GoRoute(path: '/user/navigation', builder: (c, s) => const NavigationModeScreen()),
GoRoute(path: '/user/settings', builder: (c, s) => const UserSettingsScreen()),
GoRoute(path: '/user/pairing', builder: (c, s) => const UserPairingScreen()),
GoRoute(path: '/user/call', builder: (c, s) => const CallScreen()),
],
),
// ── GUARDIAN SHELL ──────────────────────────────────────────────────────
ShellRoute(
builder: (context, state, child) => GuardianShell(child: child),
routes: [
GoRoute(path: '/guardian/dashboard', builder: (c, s) => const GuardianDashboardScreen()),
GoRoute(path: '/guardian/map', builder: (c, s) => const GuardianMapScreen()),
GoRoute(path: '/guardian/logs', builder: (c, s) => const GuardianActivityLogScreen()),
GoRoute(path: '/guardian/send-notif', builder: (c, s) => const GuardianSendNotifScreen()),
GoRoute(path: '/guardian/ai-config', builder: (c, s) => const GuardianAiConfigScreen()),
GoRoute(path: '/guardian/voice-cmd', builder: (c, s) => const GuardianVoiceCmdScreen()),
GoRoute(path: '/guardian/shortcuts', builder: (c, s) => const GuardianShortcutScreen()),
GoRoute(path: '/guardian/geofence', builder: (c, s) => const GuardianGeofenceScreen()),
GoRoute(path: '/guardian/pairing', builder: (c, s) => const GuardianPairingScreen()),
],
),
],
);