130 lines
4.5 KiB
Dart
130 lines
4.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import '../../features/auth/screens/login_screen.dart';
|
|
import '../../features/auth/screens/register_screen.dart';
|
|
import '../../features/auth/screens/two_factor_screen.dart';
|
|
import '../../features/auth/screens/forgot_password_screen.dart';
|
|
import '../../features/auth/screens/reset_password_screen.dart';
|
|
import '../../features/dashboard/dashboard_screen.dart';
|
|
import '../../features/ideas/screens/idea_list_screen.dart';
|
|
import '../../features/ideas/screens/idea_view_screen.dart';
|
|
import '../../features/ideas/screens/idea_create_screen.dart';
|
|
import '../../features/ideas/screens/idea_edit_screen.dart';
|
|
import '../../features/voice/screens/voice_input_screen.dart';
|
|
import '../../features/voice/screens/voice_sessions_screen.dart';
|
|
import '../../features/workspaces/screens/workspace_list_screen.dart';
|
|
import '../../features/workspaces/screens/workspace_detail_screen.dart';
|
|
import '../../features/notifications/notifications_screen.dart';
|
|
import '../../features/settings/screens/settings_screen.dart';
|
|
import '../../features/admin/screens/admin_screen.dart';
|
|
import '../../features/onboarding/onboarding_screen.dart';
|
|
import '../../widgets/shell.dart';
|
|
import '../api/client.dart';
|
|
import '../constants/app_constants.dart';
|
|
|
|
final _storage = FlutterSecureStorage();
|
|
|
|
final routerProvider = Provider<GoRouter>((ref) {
|
|
final apiClient = ref.read(apiClientProvider);
|
|
return GoRouter(
|
|
initialLocation: '/',
|
|
redirect: (context, state) async {
|
|
final token = await apiClient.getAccessToken();
|
|
final onboardingSeen =
|
|
await _storage.read(key: AppConstants.onboardingSeenKey);
|
|
final isAuthRoute = state.matchedLocation.startsWith('/auth') ||
|
|
state.matchedLocation == '/onboarding';
|
|
if (token == null && !isAuthRoute) {
|
|
if (onboardingSeen == null) return '/onboarding';
|
|
return '/auth/login';
|
|
}
|
|
if (token != null && isAuthRoute) return '/';
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: '/onboarding',
|
|
builder: (_, __) => const OnboardingScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/auth/login',
|
|
builder: (_, __) => const LoginScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/auth/register',
|
|
builder: (_, __) => const RegisterScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/auth/2fa',
|
|
builder: (_, __) => const TwoFactorScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/auth/forgot-password',
|
|
builder: (_, __) => const ForgotPasswordScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/auth/reset-password',
|
|
builder: (_, __) => const ResetPasswordScreen(),
|
|
),
|
|
ShellRoute(
|
|
builder: (_, __, child) => Shell(child: child),
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
builder: (_, __) => const DashboardScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/ideas',
|
|
builder: (_, __) => const IdeaListScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/ideas/create',
|
|
builder: (_, __) => const IdeaCreateScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/ideas/:id',
|
|
builder: (_, state) =>
|
|
IdeaViewScreen(id: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: '/ideas/:id/edit',
|
|
builder: (_, state) =>
|
|
IdeaEditScreen(id: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: '/voice',
|
|
builder: (_, __) => const VoiceInputScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/voice/sessions',
|
|
builder: (_, __) => const VoiceSessionsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/workspaces',
|
|
builder: (_, __) => const WorkspaceListScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/workspaces/:id',
|
|
builder: (_, state) =>
|
|
WorkspaceDetailScreen(id: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: '/notifications',
|
|
builder: (_, __) => const NotificationsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/settings',
|
|
builder: (_, __) => const SettingsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/admin',
|
|
builder: (_, __) => const AdminScreen(),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
});
|