-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.dart
173 lines (162 loc) · 6.16 KB
/
main.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
169
170
171
172
173
import 'package:account_service/account_service.dart';
import 'package:authentication_service/authentication_service.dart';
import 'package:constants_service/constants_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gallery/l10n/index.dart';
import 'package:gallery/presentation/routers/index.dart';
import 'package:gallery/presentation/screens/album/view/album.dart';
import 'package:gallery_service/gallery_service.dart';
import 'package:layout_service/layout_service.dart';
import 'package:options_service/options_service.dart';
import 'package:routers_service/routers_service.dart';
import 'package:themes_service/themes_service.dart';
void main() {
// Do something when app faced an error on release
FlutterError.onError = (details) {
FlutterError.dumpErrorToConsole(details);
// if (!kReleaseMode) {
// exit(1);
// }
};
//todo: should fix this for build mode in Github Page
// UrlStrategy.configure();
runApp(GalleryApp());
}
class GalleryApp extends StatefulWidget {
GalleryApp({
Key? key,
this.isTestMode = false,
this.initialRoute,
}) : super(key: key);
final bool isTestMode;
final String? initialRoute;
@override
_GalleryAppState createState() => _GalleryAppState();
}
class _GalleryAppState extends State<GalleryApp> {
final GalleryRouteInformationParser routeInformationParser =
GalleryRouteInformationParser();
final authenticationRepository = AuthenticationRepository();
final accountRepository = AccountRepository();
late final GalleryRouterDelegate routerDelegate;
late final GalleryRoutersState routerState;
@override
void initState() {
routerState = GalleryRoutersState();
routerDelegate = GalleryRouterDelegate(routerState);
super.initState();
}
@override
void dispose() {
routerDelegate.dispose();
routerState.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ModelBinding(
initialModel: GalleryOptions(
themeMode: ThemeMode.system,
textScaleFactor: systemTextScaleFactorOption,
// locale: Locale('fa'),
platform: defaultTargetPlatform,
isTestMode: widget.isTestMode,
),
child: Builder(
builder: (context) {
return MultiRepositoryProvider(
providers: [
RepositoryProvider(create: (_) => authenticationRepository),
RepositoryProvider(create: (_) => accountRepository),
],
child: BlocProvider(
create: (_) => AuthenticationBloc(
authenticationRepository: authenticationRepository,
accountRepository: accountRepository,
),
child: AdaptiveDesign(
material: MaterialApp.router(
title: galleryTitle,
onGenerateTitle: (context) =>
GalleryLocalizations.of(context)!.galleryTitle,
debugShowCheckedModeBanner: false,
themeMode: GalleryOptions.of(context).themeMode,
theme: GalleryThemeData.lightThemeData(context)
.copyWith(platform: GalleryOptions.of(context).platform),
darkTheme: GalleryThemeData.darkThemeData(context)
.copyWith(platform: GalleryOptions.of(context).platform),
localizationsDelegates:
GalleryLocalizations.localizationsDelegates,
supportedLocales: GalleryLocalizations.supportedLocales,
locale: GalleryOptions.of(context).locale,
localeResolutionCallback: (locale, supportedLocales) {
deviceLocale = locale;
return locale;
},
routerDelegate: routerDelegate,
routeInformationParser: routeInformationParser,
builder: (context, child) {
return ApplyTextOptions(
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: GalleryOptions.of(context)
.resolvedSystemUiOverlayStyle(context),
child: child!,
),
);
},
),
cupertino: CupertinoApp.router(
title: galleryTitle,
onGenerateTitle: (context) =>
GalleryLocalizations.of(context)!.galleryTitle,
debugShowCheckedModeBanner: false,
theme: MaterialBasedCupertinoThemeData(
materialTheme:
GalleryOptions.of(context).themeData(context),
),
localizationsDelegates:
GalleryLocalizations.localizationsDelegates,
supportedLocales: GalleryLocalizations.supportedLocales,
locale: GalleryOptions.of(context).locale,
localeResolutionCallback: (locale, supportedLocales) {
deviceLocale = locale;
return locale;
},
routerDelegate: routerDelegate,
routeInformationParser: routeInformationParser,
builder: (context, child) {
return ApplyTextOptions(
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: GalleryOptions.of(context)
.resolvedSystemUiOverlayStyle(context),
child: child!,
),
);
},
),
),
),
);
},
),
);
}
}
class RootPage extends StatelessWidget {
RootPage({
Key? key,
required this.albumPath,
this.gallery,
}) : super(key: key);
final String albumPath;
final Gallery? gallery;
@override
Widget build(BuildContext context) {
return AlbumPage(albumPath: albumPath, gallery: gallery);
// return const SplashPage();
}
}