Line data Source code
1 : import 'package:flutter/material.dart';
2 : import 'package:get/get.dart';
3 : import 'package:get/src/routes/get_route.dart';
4 : import '../get_instance.dart';
5 : import 'parse_route.dart';
6 : import 'root_controller.dart';
7 : import 'smart_management.dart';
8 :
9 : class GetMaterialApp extends StatelessWidget {
10 4 : const GetMaterialApp({
11 : Key key,
12 : this.navigatorKey,
13 : this.home,
14 : this.routes = const <String, WidgetBuilder>{},
15 : this.initialRoute,
16 : this.onGenerateRoute,
17 : this.onGenerateInitialRoutes,
18 : this.onUnknownRoute,
19 : this.navigatorObservers = const <NavigatorObserver>[],
20 : this.builder,
21 : this.title = '',
22 : this.onGenerateTitle,
23 : this.color,
24 : this.onInit,
25 : this.onDispose,
26 : this.theme,
27 : this.darkTheme,
28 : this.themeMode = ThemeMode.system,
29 : this.locale,
30 : this.localizationsDelegates,
31 : this.localeListResolutionCallback,
32 : this.localeResolutionCallback,
33 : this.supportedLocales = const <Locale>[Locale('en', 'US')],
34 : this.debugShowMaterialGrid = false,
35 : this.showPerformanceOverlay = false,
36 : this.checkerboardRasterCacheImages = false,
37 : this.checkerboardOffscreenLayers = false,
38 : this.showSemanticsDebugger = false,
39 : this.debugShowCheckedModeBanner = true,
40 : this.shortcuts,
41 : this.smartManagement = SmartManagement.full,
42 : this.initialBinding,
43 : this.routingCallback,
44 : this.defaultTransition,
45 : // this.actions,
46 : this.getPages,
47 : this.opaqueRoute,
48 : this.enableLog,
49 : this.popGesture,
50 : this.transitionDuration,
51 : this.defaultGlobalState,
52 : this.unknownRoute,
53 1 : }) : assert(routes != null),
54 1 : assert(navigatorObservers != null),
55 1 : assert(title != null),
56 2 : assert(debugShowMaterialGrid != null),
57 1 : assert(showPerformanceOverlay != null),
58 1 : assert(checkerboardRasterCacheImages != null),
59 1 : assert(checkerboardOffscreenLayers != null),
60 1 : assert(showSemanticsDebugger != null),
61 1 : assert(debugShowCheckedModeBanner != null),
62 3 : super(key: key);
63 :
64 : final GlobalKey<NavigatorState> navigatorKey;
65 : final Widget home;
66 : final Map<String, WidgetBuilder> routes;
67 : final String initialRoute;
68 : final RouteFactory onGenerateRoute;
69 : final InitialRouteListFactory onGenerateInitialRoutes;
70 : final RouteFactory onUnknownRoute;
71 : final List<NavigatorObserver> navigatorObservers;
72 : final TransitionBuilder builder;
73 : final String title;
74 : final GenerateAppTitle onGenerateTitle;
75 : final ThemeData theme;
76 : final ThemeData darkTheme;
77 : final ThemeMode themeMode;
78 : final Color color;
79 : final Locale locale;
80 : final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates;
81 : final LocaleListResolutionCallback localeListResolutionCallback;
82 : final LocaleResolutionCallback localeResolutionCallback;
83 : final Iterable<Locale> supportedLocales;
84 : final bool showPerformanceOverlay;
85 : final bool checkerboardRasterCacheImages;
86 : final bool checkerboardOffscreenLayers;
87 : final bool showSemanticsDebugger;
88 : final bool debugShowCheckedModeBanner;
89 : final Map<LogicalKeySet, Intent> shortcuts;
90 : // final Map<LocalKey, ActionFactory> actions;
91 : final bool debugShowMaterialGrid;
92 : final Function(Routing) routingCallback;
93 : final Transition defaultTransition;
94 : final bool opaqueRoute;
95 : final VoidCallback onInit;
96 : final VoidCallback onDispose;
97 : final bool enableLog;
98 : final bool popGesture;
99 : final SmartManagement smartManagement;
100 : final Bindings initialBinding;
101 : final Duration transitionDuration;
102 : final bool defaultGlobalState;
103 : final List<GetPage> getPages;
104 : final GetRoute unknownRoute;
105 :
106 1 : Route<dynamic> generator(RouteSettings settings) {
107 2 : final match = _routeTree.matchRoute(settings.name);
108 3 : Get.parameters = match?.parameters;
109 :
110 1 : return GetPageRoute(
111 2 : page: match.route.page,
112 2 : parameter: match.route.parameter,
113 : settings:
114 3 : RouteSettings(name: settings.name, arguments: settings.arguments),
115 2 : curve: match.route.curve,
116 2 : opaque: match.route.opaque,
117 2 : binding: match.route.binding,
118 2 : bindings: match.route.bindings,
119 1 : duration: (transitionDuration == null
120 2 : ? match.route.transitionDuration
121 0 : : transitionDuration),
122 2 : transition: match.route.transition,
123 2 : popGesture: match.route.popGesture,
124 2 : fullscreenDialog: match.route.fullscreenDialog,
125 : );
126 : }
127 :
128 3 : @override
129 : Widget build(BuildContext context) {
130 3 : return GetBuilder<GetMaterialController>(
131 6 : init: Get.GetxController,
132 3 : dispose: (d) {
133 3 : onDispose?.call();
134 : },
135 3 : initState: (i) {
136 3 : initialBinding?.dependencies();
137 3 : if (getPages != null) {
138 1 : _routeTree = ParseRouteTree();
139 3 : getPages.forEach((element) {
140 1 : _routeTree.addRoute(element);
141 : });
142 : }
143 3 : GetConfig.smartManagement = smartManagement;
144 3 : onInit?.call();
145 :
146 6 : Get.config(
147 3 : enableLog: enableLog ?? GetConfig.isLogEnable,
148 9 : defaultTransition: defaultTransition ?? Get.defaultTransition,
149 9 : defaultOpaqueRoute: opaqueRoute ?? Get.isOpaqueRouteDefault,
150 9 : defaultPopGesture: popGesture ?? Get.isPopGestureEnable,
151 : defaultDurationTransition:
152 9 : transitionDuration ?? Get.defaultDurationTransition,
153 9 : defaultGlobalState: defaultGlobalState ?? Get.defaultGlobalState,
154 : );
155 : },
156 3 : builder: (_) {
157 3 : return MaterialApp(
158 3 : key: key,
159 : navigatorKey:
160 9 : (navigatorKey == null ? Get.key : Get.addKey(navigatorKey)),
161 3 : home: home,
162 3 : routes: routes ?? const <String, WidgetBuilder>{},
163 3 : initialRoute: initialRoute,
164 7 : onGenerateRoute: (getPages != null ? generator : onGenerateRoute),
165 3 : onGenerateInitialRoutes: onGenerateInitialRoutes ??
166 4 : (getPages == null || home != null)
167 : ? null
168 0 : : (st) {
169 : GetPageMatch match;
170 0 : if (initialRoute == null && getPages != null) {
171 0 : match = _routeTree?.matchRoute(getPages.first.name);
172 : } else {
173 0 : match = _routeTree?.matchRoute(initialRoute);
174 : }
175 :
176 0 : Get.parameters = match?.parameters;
177 0 : return [
178 0 : GetPageRoute(
179 0 : page: match.route.page,
180 0 : parameter: match.parameters,
181 : settings:
182 0 : RouteSettings(name: initialRoute, arguments: null),
183 0 : curve: match.route.curve,
184 0 : opaque: match.route.opaque,
185 0 : binding: match.route.binding,
186 0 : bindings: match.route.bindings,
187 0 : duration: (transitionDuration == null
188 0 : ? match.route.transitionDuration
189 0 : : transitionDuration),
190 0 : transition: match.route.transition,
191 0 : popGesture: match.route.popGesture,
192 0 : fullscreenDialog: match.route.fullscreenDialog,
193 : )
194 : ];
195 : },
196 3 : onUnknownRoute: onUnknownRoute,
197 3 : navigatorObservers: (navigatorObservers == null
198 0 : ? <NavigatorObserver>[GetObserver(routingCallback)]
199 9 : : <NavigatorObserver>[GetObserver(routingCallback)]
200 6 : ..addAll(navigatorObservers)),
201 3 : builder: builder,
202 3 : title: title ?? '',
203 3 : onGenerateTitle: onGenerateTitle,
204 3 : color: color,
205 9 : theme: _.theme ?? theme ?? ThemeData.fallback(),
206 3 : darkTheme: darkTheme,
207 6 : themeMode: _.themeMode ?? themeMode ?? ThemeMode.system,
208 3 : locale: locale,
209 3 : localizationsDelegates: localizationsDelegates,
210 3 : localeListResolutionCallback: localeListResolutionCallback,
211 3 : localeResolutionCallback: localeResolutionCallback,
212 : supportedLocales:
213 3 : supportedLocales ?? const <Locale>[Locale('en', 'US')],
214 3 : debugShowMaterialGrid: debugShowMaterialGrid ?? false,
215 3 : showPerformanceOverlay: showPerformanceOverlay ?? false,
216 : checkerboardRasterCacheImages:
217 3 : checkerboardRasterCacheImages ?? false,
218 3 : checkerboardOffscreenLayers: checkerboardOffscreenLayers ?? false,
219 3 : showSemanticsDebugger: showSemanticsDebugger ?? false,
220 3 : debugShowCheckedModeBanner: debugShowCheckedModeBanner ?? true,
221 3 : shortcuts: shortcuts,
222 : // actions: actions,
223 : );
224 : });
225 : }
226 : }
227 :
228 : ParseRouteTree _routeTree;
|