-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp_view.dart
135 lines (129 loc) · 5.27 KB
/
app_view.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
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_cbl_learning_path/features/router/route.dart';
import 'package:flutter_cbl_learning_path/features/project/project.dart';
import 'package:flutter_cbl_learning_path/features/audit/audit.dart';
import 'package:flutter_cbl_learning_path/features/login/login.dart';
import 'package:flutter_cbl_learning_path/features/splash/splash.dart';
import 'package:flutter_cbl_learning_path/features/developer/developer.dart';
import 'package:flutter_cbl_learning_path/features/replicator/replicator.dart';
import 'package:flutter_cbl_learning_path/theme/palette.dart';
class AppView extends StatefulWidget {
const AppView({super.key});
@override
State<AppView> createState() => _AppViewState();
}
class _AppViewState extends State<AppView> {
final _navigatorKey = GlobalKey<NavigatorState>();
NavigatorState get _navigator => _navigatorKey.currentState!;
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: _navigatorKey,
title: 'Inventory Audit',
routes: {
"/login": (context) => const LoginScreen(),
"/projects": (context) => ProjectListScreen(
routerService: RepositoryProvider.of<AppRouterService>(context)),
"/projectEditor": (context) => ProjectEditorScreen(
routerService: RepositoryProvider.of<AppRouterService>(context)),
"/audits": (context) => AuditListScreen(
routerService: RepositoryProvider.of<AppRouterService>(context)),
"/auditEditor": (context) => AuditEditorScreen(
routerService: RepositoryProvider.of<AppRouterService>(context)),
"/dev": (context) => DeveloperMenuScreen(
routerService: RepositoryProvider.of<AppRouterService>(context)),
"/devInfo": (context) => DeveloperInfoScreen(
routerService: RepositoryProvider.of<AppRouterService>(context)),
"/devLoadSampleData": (context) => const DeveloperSampleDataScreen(),
"/replicator": (context) => ReplicatorScreen(routerService: RepositoryProvider.of<AppRouterService>(context)),
},
theme: ThemeData(
primarySwatch: Palette.couchbaseRed,
backgroundColor: Palette.couchbaseRed,
buttonTheme: const ButtonThemeData(
buttonColor: Palette.couchbaseRed,
textTheme: ButtonTextTheme.primary,
),
),
builder: (context, child) {
return MultiBlocListener(
listeners: [
BlocListener<RouteBloc, RouteState>(listener: (context, state) {
if (state.status == AuthenticationStatus.authenticated) {
switch (state.route.routeToScreen) {
case RouteToScreen.projects:
{
_navigator.pushNamedAndRemoveUntil(
"/projects", (route) => false);
ScaffoldMessenger.of(context).hideCurrentSnackBar();
}
break;
case RouteToScreen.projectEditor:
{
_navigator.pushNamed("/projectEditor",
arguments: {state.route});
}
break;
case RouteToScreen.audits:
{
_navigator.pushNamed("/audits", arguments: {state.route});
}
break;
case RouteToScreen.auditEditor:
{
_navigator
.pushNamed("/auditEditor", arguments: {state.route});
}
break;
case RouteToScreen.userProfileEditor:
{
_navigator.pushNamed("/userProfileEditor");
}
break;
case RouteToScreen.developer:
{
_navigator.pushNamedAndRemoveUntil(
"/dev", (route) => false);
}
break;
case RouteToScreen.developerInfo:
{
_navigator.pushNamed("/devInfo");
}
break;
case RouteToScreen.replicator:
{
_navigator.pushNamedAndRemoveUntil(
"/replicator", (route) => false);
}
break;
case RouteToScreen.replicatorConfig:
{
_navigator.pushNamed("/replicatorConfig");
}
break;
case RouteToScreen.pop:
{
_navigator.pop();
}
break;
//not needed to handled
default:
break;
}
} else {
if (state.status != AuthenticationStatus.authenticatedFailed) {
_navigator.pushAndRemoveUntil(
LoginScreen.route(), (route) => false);
}
}
}),
],
child: child!,
);
},
onGenerateRoute: (_) => SplashScreen.route(),
);
}
}