170 lines
5.4 KiB
Dart
170 lines
5.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../features/dashboard/dashboard_screen.dart';
|
|
import '../features/map/map_screen.dart';
|
|
import '../features/history/history_screen.dart';
|
|
import '../features/records/records_screen.dart';
|
|
import '../features/settings/settings_screen.dart';
|
|
import '../features/settings/diagnostics_screen.dart';
|
|
import '../features/garage/garage_screen.dart';
|
|
import '../features/garage/add_motorcycle_screen.dart';
|
|
import '../features/garage/motorcycle_detail_screen.dart';
|
|
import 'widgets/main_layout.dart';
|
|
|
|
import '../features/settings/field_test_report_screen.dart';
|
|
import '../features/settings/field_test_live_log_screen.dart';
|
|
import '../features/field_test/field_test_pre_ride_check_screen.dart';
|
|
import '../features/settings/oauth_callback_screen.dart';
|
|
import '../features/settings/account_screen.dart';
|
|
import '../features/entitlements/pro_screen.dart';
|
|
import '../features/social/rider_profile_screen.dart';
|
|
import '../features/social/friends_screen.dart';
|
|
|
|
// ignore: unused_element
|
|
final _rootNavigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
final appRouter = GoRouter(
|
|
initialLocation: '/',
|
|
errorBuilder: (context, state) {
|
|
final uri = state.uri;
|
|
if (uri.toString().contains('oauth') || uri.toString().contains('code=')) {
|
|
return OAuthCallbackScreen(uri: uri);
|
|
}
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
body: Center(
|
|
child: Text(
|
|
'Navigation Error: ${state.error}',
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
redirect: (context, state) {
|
|
final uri = state.uri;
|
|
final uriStr = uri.toString();
|
|
if (uri.scheme == 'motorsignal' ||
|
|
uri.host == 'oauth' ||
|
|
uriStr.contains('/oauth/callback')) {
|
|
if (state.matchedLocation != '/oauth/callback') {
|
|
return '/oauth/callback?${uri.query}';
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: '/oauth/callback',
|
|
builder: (context, state) => OAuthCallbackScreen(uri: state.uri),
|
|
),
|
|
StatefulShellRoute.indexedStack(
|
|
builder: (context, state, navigationShell) {
|
|
return MainLayout(navigationShell: navigationShell);
|
|
},
|
|
branches: [
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
builder: (context, state) => const DashboardScreen(),
|
|
),
|
|
],
|
|
),
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/map',
|
|
builder: (context, state) => const MapScreen(),
|
|
),
|
|
],
|
|
),
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/history',
|
|
builder: (context, state) => const HistoryScreen(),
|
|
),
|
|
],
|
|
),
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/records',
|
|
builder: (context, state) => const RecordsScreen(),
|
|
),
|
|
],
|
|
),
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/garage',
|
|
builder: (context, state) => const GarageScreen(),
|
|
routes: [
|
|
GoRoute(
|
|
path: 'add',
|
|
builder: (context, state) => const AddMotorcycleScreen(),
|
|
),
|
|
GoRoute(
|
|
path: ':id',
|
|
builder: (context, state) {
|
|
final id = int.parse(state.pathParameters['id']!);
|
|
return MotorcycleDetailScreen(motorcycleId: id);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
StatefulShellBranch(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/settings',
|
|
builder: (context, state) => const SettingsScreen(),
|
|
routes: [
|
|
GoRoute(
|
|
path: 'account',
|
|
builder: (context, state) => const AccountScreen(),
|
|
),
|
|
GoRoute(
|
|
path: 'pro',
|
|
builder: (context, state) => const ProScreen(),
|
|
),
|
|
GoRoute(
|
|
path: 'profile',
|
|
builder: (context, state) => const RiderProfileScreen(),
|
|
),
|
|
GoRoute(
|
|
path: 'friends',
|
|
builder: (context, state) => const FriendsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: 'diagnostics',
|
|
builder: (context, state) => const DiagnosticsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: 'field-test-report',
|
|
builder: (context, state) {
|
|
final rideId = state.uri.queryParameters['rideId'] != null
|
|
? int.tryParse(state.uri.queryParameters['rideId']!)
|
|
: null;
|
|
return FieldTestReportScreen(rideId: rideId);
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: 'field-test-live-log',
|
|
builder: (context, state) => const FieldTestLiveLogScreen(),
|
|
),
|
|
GoRoute(
|
|
path: 'field-test-pre-ride-check',
|
|
builder: (context, state) =>
|
|
const FieldTestPreRideCheckScreen(),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|