-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_router.dart
168 lines (162 loc) · 6.56 KB
/
app_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
158
159
160
161
162
163
164
165
166
167
168
import 'package:auto_route/auto_route.dart';
import 'package:flutter/cupertino.dart';
import 'package:logging/logging.dart';
import 'package:repaint_mobile/config/guards.dart';
import 'package:repaint_mobile/config/route.dart';
import 'package:repaint_mobile/features/common/domain/entities/user_entity.dart';
import 'package:repaint_mobile/features/common/presentation/screens/oss_licenses_detail_screen.dart';
import 'package:repaint_mobile/features/common/presentation/screens/oss_licenses_screen.dart';
import 'package:repaint_mobile/features/introduction/presentation/screens/introduction_manual_screen.dart';
import 'package:repaint_mobile/features/introduction/presentation/screens/introduction_qrcode_reader_screen.dart';
import 'package:repaint_mobile/features/introduction/presentation/screens/introduction_settings_screen.dart';
import 'package:repaint_mobile/features/introduction/presentation/screens/introduction_stepper_screen.dart';
import 'package:repaint_mobile/features/introduction/presentation/screens/introduction_welcome_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_beacon_list_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_beacon_settings_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_camera_preview_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_camera_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_event_list_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_home_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_qrcode_reader_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_settings_screen.dart';
import 'package:repaint_mobile/features/operator/presentation/screens/operator_stepper_screen.dart';
import 'package:repaint_mobile/features/visitor/presentation/screens/visitor_home_screen.dart';
import 'package:repaint_mobile/features/visitor/presentation/screens/visitor_images_screen.dart';
import 'package:repaint_mobile/features/visitor/presentation/screens/visitor_qrcode_reader_screen.dart';
import 'package:repaint_mobile/features/visitor/presentation/screens/visitor_settings_screen.dart';
part 'app_router.gr.dart';
@AutoRouterConfig(replaceInRouteName: 'Screen,Route')
class AppRouter extends _$AppRouter implements AutoRouteGuard {
AppRouter(
this._user,
this._permissionGuard,
) : super();
final CommonUserEntity? _user;
final PermissionGuard _permissionGuard;
static final Logger _logger = Logger("AppRouter");
bool _isInitialized = false;
@override
Future<void> onNavigation(
NavigationResolver resolver,
StackRouter router,
) async {
final currentUserType = _user?.type.name.split('.').last;
final nextUserPath = resolver.route.path.split('/').elementAtOrNull(1);
final nextUserType =
nextUserPath == 'introduction' ? 'unknown' : nextUserPath;
_logger.info('user type: $currentUserType -> $nextUserType');
if (_isInitialized ||
currentUserType == nextUserType ||
resolver.route.path == "/operator/stepper" ||
resolver.route.path == "/operator/events" ||
resolver.route.path.contains("/licenses")) {
_logger.info(
'from ${router.currentPath} to ${resolver.route.path} as ${_user?.type}',
);
resolver.next();
} else {
_isInitialized = true;
if (_user?.type == UserType.visitor) {
_logger.info('redirect to visitor');
await resolver.redirect(const VisitorHomeRoute());
} else if (_user?.type == UserType.operator) {
_logger.info('redirect to operator');
await resolver.redirect(const OperatorHomeRoute());
} else {
_logger.info('default page');
await resolver.redirect(const IntroductionWelcomeRoute());
}
}
}
@override
List<RepaintRoute> get routes => [
RepaintRoute(
path: '/introduction/welcome',
page: IntroductionWelcomeRoute.page,
initial: true,
),
RepaintRoute(
path: '/introduction/manual',
page: IntroductionManualRoute.page,
),
RepaintRoute(
path: '/introduction/stepper',
page: IntroductionStepperRoute.page,
),
RepaintRoute(
path: '/introduction/qrcode_reader',
page: IntroductionQRCodeReaderRoute.page,
guards: [_permissionGuard],
),
RepaintRoute(
path: '/introduction/settings',
page: IntroductionSettingsRoute.page,
),
RepaintRoute(
path: '/visitor/home',
page: VisitorHomeRoute.page,
),
RepaintRoute(
path: '/visitor/qrcode_reader',
page: VisitorQRCodeReaderRoute.page,
guards: [_permissionGuard],
),
RepaintRoute(
path: '/visitor/images',
page: VisitorImagesRoute.page,
),
RepaintRoute(
path: '/visitor/settings',
page: VisitorSettingsRoute.page,
),
RepaintRoute(
path: '/operator/stepper',
page: OperatorStepperRoute.page,
),
RepaintRoute(
path: '/operator/home',
page: OperatorHomeRoute.page,
),
RepaintRoute(
path: '/operator/events',
page: OperatorEventListRoute.page,
),
RepaintRoute(
path: '/operator/qrcode_reader',
page: OperatorQRCodeReaderRoute.page,
guards: [_permissionGuard],
),
RepaintRoute(
path: '/operator/camera',
page: OperatorCameraRoute.page,
guards: [_permissionGuard],
),
RepaintRoute(
path: '/operator/camera/preview',
page: OperatorCameraPreviewRoute.page,
guards: [_permissionGuard],
),
RepaintRoute(
path: '/operator/beacon',
page: OperatorBeaconListRoute.page,
guards: [_permissionGuard],
),
RepaintRoute(
path: '/operator/beacon/settings',
page: OperatorBeaconSettingsRoute.page,
guards: [_permissionGuard],
),
RepaintRoute(
path: '/operator/settings',
page: OperatorSettingsRoute.page,
),
RepaintRoute(
path: '/licenses',
page: OssLicensesRoute.page,
),
RepaintRoute(
path: '/licenses/detail',
page: OssLicensesDetailRoute.page,
),
];
}