-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathapp.dart
87 lines (76 loc) · 2.71 KB
/
app.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
import 'package:auth/src/app_router.dart';
import 'package:auth/src/features/auth/logic/cubit/auth_cubit.dart';
import 'package:auth/src/features/auth/logic/models/user.dart';
import 'package:auth/src/features/auth/logic/repository/auth_repository.dart';
import 'package:auth/src/features/home/views/screens/home_screen.dart';
import 'package:auth/src/features/notification/logic/repository/notification_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
final GlobalKey<NavigatorState> applicationKey = GlobalKey();
final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey = GlobalKey();
class MyApp extends StatefulWidget {
MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final appRouter = AppRouter();
@override
void initState() {
super.initState();
notificationRepository.init();
}
@override
Widget build(BuildContext context) {
return _InitProviders(
child: MaterialApp(
navigatorKey: applicationKey,
scaffoldMessengerKey: scaffoldMessengerKey,
debugShowCheckedModeBanner: false,
initialRoute: HomeScreen.routeName,
onGenerateRoute: appRouter.onGenerateRoute,
theme: ThemeData.light().copyWith(
colorScheme: ColorScheme.light().copyWith(
primary: Color(0xff4C525C),
secondary: Color(0xff4C525C),
background: Color(0xff4C525C),
),
appBarTheme: AppBarTheme(elevation: 0),
primaryColor: Color(0xff4C525C),
secondaryHeaderColor: Color(0xffFFAE48),
highlightColor: Color(0xff58BFE6),
indicatorColor: Color(0xff4C525C),
),
),
);
}
}
class _InitProviders extends StatelessWidget {
final Widget child;
const _InitProviders({Key? key, required this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return RepositoryProvider(
create: (context) => AuthRepository(),
child: BlocProvider(
create: (context) => AuthCubit(
authRepository: context.read<AuthRepository>(),
),
child: BlocListener<AuthCubit, User?>(
listenWhen: (prev, curr) => prev != null && curr == null,
listener: (context, user) {
final route = ModalRoute.of(context)?.settings.name;
if (user == null && route != HomeScreen.routeName) {
Navigator.pushNamedAndRemoveUntil(
applicationKey.currentContext as BuildContext,
HomeScreen.routeName,
(route) => false,
);
}
},
child: child,
),
),
);
}
}