-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.dart
65 lines (62 loc) · 1.98 KB
/
router.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'package:flutter/material.dart';
import 'package:flutter_bootstrap_app/views/home/home.screen.dart';
import 'package:flutter_bootstrap_app/views/login/login.screen.dart';
import 'package:flutter_bootstrap_app/views/onboarding/onboarding.screen.dart';
import 'package:flutter_bootstrap_app/views/splash/splash.screen.dart';
import 'package:flutter_bootstrap_app/views/subscriptions/subscriptions.screen.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
enum AppRoute {
splash,
onboarding,
login,
home,
subscriptions,
}
/// Returns the path for the given route
/// Uses [route] The route to get the path for and an optional [id]
/// if needed
String appRoutesPath(AppRoute route, {String? id}) => switch (route) {
AppRoute.splash => '/splash',
AppRoute.onboarding => '/onboarding',
AppRoute.login => '/login',
AppRoute.home => '/',
AppRoute.subscriptions => '/subscriptions',
};
final routerProvider = Provider<GoRouter>((ref) {
return GoRouter(
initialLocation: appRoutesPath(AppRoute.splash),
routes: [
GoRoute(
path: appRoutesPath(AppRoute.splash),
pageBuilder: (context, state) => const MaterialPage(
child: SplashScreen(),
),
),
GoRoute(
path: appRoutesPath(AppRoute.onboarding),
pageBuilder: (context, state) => const MaterialPage(
child: OnboardingScreen(),
),
),
GoRoute(
path: appRoutesPath(AppRoute.login),
pageBuilder: (context, state) => const MaterialPage(
child: LoginScreen(),
),
),
GoRoute(
path: appRoutesPath(AppRoute.home),
pageBuilder: (context, state) => const MaterialPage(
child: HomeScreen(),
),
),
GoRoute(
path: appRoutesPath(AppRoute.subscriptions),
pageBuilder: (context, state) => const MaterialPage(
child: SubscriptionsScreen(),
),
),
],
);
});