-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrouter.dart
157 lines (151 loc) · 5.21 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold_example/app_scaffold.dart';
import 'package:flutter_adaptive_scaffold_example/details_screen.dart';
import 'package:flutter_adaptive_scaffold_example/nav_list_screen.dart';
import 'package:go_router/go_router.dart';
final _nav1NavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'nav1');
final _nav2NavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'nav2');
final _nav3NavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'nav3');
final _rootNavigatorKey = GlobalKey<NavigatorState>();
class AppRouter {
// Navigator Tab Screens
static const nav1 = "/nav1";
static const nav2 = "/nav2";
static const nav3 = "/nav3";
// List screens
static const nav1Details = "nav1Details";
static const nav2Details = "nav2Details";
static const nav3Details = "nav3Details";
static final router = GoRouter(
errorBuilder: (context, state) => Container(color: Colors.red),
navigatorKey: _rootNavigatorKey,
initialLocation: "/",
debugLogDiagnostics: true,
routes: <RouteBase>[
GoRoute(
path: "/",
redirect: (_, __) => AppRouter.nav1,
),
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) {
return AppScaffoldShell(
navigationShell: navigationShell,
);
},
branches: <StatefulShellBranch>[
// Nav1 branch
StatefulShellBranch(
initialLocation: AppRouter.nav1,
navigatorKey: _nav1NavigatorKey,
routes: [
GoRoute(
name: AppRouter.nav1,
path: AppRouter.nav1,
pageBuilder: (context, state) => NoTransitionPage(
child: AppScaffold(
body: NavListScreen(
key: state.pageKey,
listId: 1,
),
),
),
routes: [
GoRoute(
name: AppRouter.nav1Details,
path: ":id",
pageBuilder: (context, state) => NoTransitionPage(
child: AppScaffold(
body: NavListScreen(
key: state.pageKey,
listId: 1,
selectedIndex: state.pathParameters["id"]!,
),
secondaryBody: DetailsScreen(
id: state.pathParameters["id"],
),
),
),
),
],
),
],
),
// Nav2 branch
StatefulShellBranch(
initialLocation: AppRouter.nav2,
navigatorKey: _nav2NavigatorKey,
routes: [
GoRoute(
name: AppRouter.nav2,
path: AppRouter.nav2,
pageBuilder: (context, state) => NoTransitionPage(
child: AppScaffold(
body: NavListScreen(
key: state.pageKey,
listId: 2,
),
),
),
routes: [
GoRoute(
name: AppRouter.nav2Details,
path: ":id",
pageBuilder: (context, state) => NoTransitionPage(
child: AppScaffold(
body: NavListScreen(
key: state.pageKey,
listId: 2,
selectedIndex: state.pathParameters["id"]!,
),
secondaryBody: DetailsScreen(
id: state.pathParameters["id"],
),
),
),
),
],
),
],
),
// Nav3 branch
StatefulShellBranch(
initialLocation: AppRouter.nav3,
navigatorKey: _nav3NavigatorKey,
routes: [
GoRoute(
name: AppRouter.nav3,
path: AppRouter.nav3,
pageBuilder: (context, state) => NoTransitionPage(
child: AppScaffold(
body: NavListScreen(
key: state.pageKey,
listId: 3,
),
),
),
routes: [
GoRoute(
name: AppRouter.nav3Details,
path: ":id",
pageBuilder: (context, state) => NoTransitionPage(
child: AppScaffold(
body: NavListScreen(
key: state.pageKey,
listId: 3,
selectedIndex: state.pathParameters["id"]!,
),
secondaryBody: DetailsScreen(
id: state.pathParameters["id"],
),
),
),
),
],
),
],
),
],
),
],
);
}