Showing
53 changed files
with
1244 additions
and
1387 deletions
1 | library get; | 1 | library get; |
2 | 2 | ||
3 | -export 'instance_manager.dart'; | ||
4 | -export 'route_manager.dart'; | ||
5 | -export 'state_manager.dart'; | ||
6 | -export 'utils.dart'; | 3 | +export 'src/instance/instance_manager.dart'; |
4 | +export 'src/navigation/route_manager.dart'; | ||
5 | +export 'src/state_manager/state_manager.dart'; | ||
6 | +export 'src/utils/utils.dart'; |
lib/instance_manager.dart
deleted
100644 → 0
lib/route_manager.dart
deleted
100644 → 0
1 | -export 'src/routes/custom_transition.dart'; | ||
2 | -export 'src/routes/transitions_type.dart'; | ||
3 | -export 'src/routes/get_route.dart'; | ||
4 | -export 'src/routes/default_route.dart'; | ||
5 | -export 'src/routes/observers/route_observer.dart'; | ||
6 | -export 'src/root/root_widget.dart'; | ||
7 | -export 'src/snackbar/snack_route.dart'; | ||
8 | -export 'src/bottomsheet/bottomsheet.dart'; | ||
9 | -export 'src/snackbar/snack.dart'; | ||
10 | -export 'src/get_main.dart'; | ||
11 | -export 'src/routes/default_route.dart'; | ||
12 | -export 'src/root/smart_management.dart'; |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | -import 'package:flutter/scheduler.dart'; | ||
3 | -import 'package:get/get.dart'; | ||
4 | -import 'root/root_controller.dart'; | ||
5 | -import 'routes/bindings_interface.dart'; | ||
6 | -import 'routes/transitions_type.dart'; | ||
7 | -import 'snackbar/snack.dart'; | 2 | +import 'navigation/root/parse_route.dart'; |
3 | +import 'navigation/root/root_controller.dart'; | ||
4 | +import 'navigation/routes/custom_transition.dart'; | ||
5 | +import 'navigation/routes/observers/route_observer.dart'; | ||
6 | +import 'navigation/routes/transitions_type.dart'; | ||
7 | +import 'utils/utils.dart'; | ||
8 | 8 | ||
9 | ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | 9 | ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, |
10 | ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | 10 | ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" |
@@ -12,289 +12,31 @@ import 'snackbar/snack.dart'; | @@ -12,289 +12,31 @@ import 'snackbar/snack.dart'; | ||
12 | ///To return to the previous screen, use Get.back(). | 12 | ///To return to the previous screen, use Get.back(). |
13 | ///No need to pass any context to Get, just put the name of the route inside | 13 | ///No need to pass any context to Get, just put the name of the route inside |
14 | ///the parentheses and the magic will occur. | 14 | ///the parentheses and the magic will occur. |
15 | -/// | ||
16 | 15 | ||
17 | -abstract class GetService { | ||
18 | - /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push | ||
19 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
20 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
21 | - Future<T> to<T>(Widget page, | ||
22 | - {bool opaque, | ||
23 | - Transition transition, | ||
24 | - Duration duration, | ||
25 | - int id, | ||
26 | - bool fullscreenDialog = false, | ||
27 | - Object arguments, | ||
28 | - Bindings binding, | ||
29 | - bool popGesture}); | 16 | +abstract class GetInterface { |
17 | + bool defaultPopGesture = GetPlatform.isIOS; | ||
18 | + bool defaultOpaqueRoute = true; | ||
19 | + Transition defaultTransition; | ||
20 | + Duration defaultDurationTransition = Duration(milliseconds: 400); | ||
21 | + bool defaultGlobalState = true; | ||
22 | + RouteSettings settings; | ||
23 | + String defaultSeparator = "_"; | ||
30 | 24 | ||
31 | - /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed | ||
32 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
33 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
34 | - Future<T> toNamed<T>(String page, {Object arguments, int id}); | 25 | + final routing = Routing(); |
35 | 26 | ||
36 | - /// It replaces Navigator.pushReplacementNamed, but needs no context. | ||
37 | - Future<T> offNamed<T>(String page, {Object arguments, int id}); | 27 | + Map<String, String> parameters = {}; |
38 | 28 | ||
39 | - /// It replaces Navigator.popUntil, but needs no context. | ||
40 | - void until(RoutePredicate predicate, {int id}); | 29 | + ParseRouteTree routeTree; |
41 | 30 | ||
42 | - /// It replaces Navigator.pushAndRemoveUntil, but needs no context. | ||
43 | - Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}); | 31 | + CustomTransition customTransition; |
44 | 32 | ||
45 | - /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | ||
46 | - Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, | ||
47 | - {int id, Object arguments}); | 33 | + GetMaterialController getxController = GetMaterialController(); |
48 | 34 | ||
49 | - /// It replaces Navigator.popAndPushNamed, but needs no context. | ||
50 | - Future<T> offAndToNamed<T>(String page, | ||
51 | - {Object arguments, int id, dynamic result}); | 35 | + Locale locale; |
52 | 36 | ||
53 | - /// It replaces Navigator.removeRoute, but needs no context. | ||
54 | - void removeRoute(Route<dynamic> route, {int id}); | 37 | + GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); |
55 | 38 | ||
56 | - /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | ||
57 | - Future<T> offAllNamed<T>(String newRouteName, | ||
58 | - {RoutePredicate predicate, Object arguments, int id}); | 39 | + Map<int, GlobalKey<NavigatorState>> keys = {}; |
59 | 40 | ||
60 | - bool get isOverlaysOpen; | ||
61 | - | ||
62 | - bool get isOverlaysClosed; | ||
63 | - | ||
64 | - /// It replaces Navigator.pop, but needs no context. | ||
65 | - void back({dynamic result, bool closeOverlays = false, int id}); | ||
66 | - | ||
67 | - /// It will close as many screens as you define. Times must be> 0; | ||
68 | - void close(int times, [int id]); | ||
69 | - | ||
70 | - /// It replaces Navigator.pushReplacement, but needs no context, and it doesn't have the Navigator.pushReplacement | ||
71 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
72 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
73 | - Future<T> off<T>(Widget page, | ||
74 | - {bool opaque = false, | ||
75 | - Transition transition, | ||
76 | - bool popGesture, | ||
77 | - int id, | ||
78 | - Object arguments, | ||
79 | - Bindings binding, | ||
80 | - bool fullscreenDialog = false, | ||
81 | - Duration duration}); | ||
82 | - | ||
83 | - /// It replaces Navigator.pushAndRemoveUntil, but needs no context | ||
84 | - Future<T> offAll<T>(Widget page, | ||
85 | - {RoutePredicate predicate, | ||
86 | - bool opaque = false, | ||
87 | - bool popGesture, | ||
88 | - int id, | ||
89 | - Object arguments, | ||
90 | - Bindings binding, | ||
91 | - bool fullscreenDialog = false, | ||
92 | - Transition transition}); | ||
93 | - | ||
94 | - /// Show a dialog | ||
95 | - Future<T> dialog<T>( | ||
96 | - Widget child, { | ||
97 | - bool barrierDismissible = true, | ||
98 | - bool useRootNavigator = true, | ||
99 | - // RouteSettings routeSettings | ||
100 | - }); | ||
101 | - | ||
102 | - /// Api from showGeneralDialog with no context | ||
103 | - Future<T> generalDialog<T>({ | ||
104 | - @required RoutePageBuilder pageBuilder, | ||
105 | - String barrierLabel = "Dismiss", | ||
106 | - bool barrierDismissible = true, | ||
107 | - Color barrierColor = const Color(0x80000000), | ||
108 | - Duration transitionDuration = const Duration(milliseconds: 200), | ||
109 | - RouteTransitionsBuilder transitionBuilder, | ||
110 | - bool useRootNavigator = true, | ||
111 | - RouteSettings routeSettings, | ||
112 | - }); | ||
113 | - | ||
114 | - Future<T> defaultDialog<T>({ | ||
115 | - String title = "Alert", | ||
116 | - Widget content, | ||
117 | - VoidCallback onConfirm, | ||
118 | - VoidCallback onCancel, | ||
119 | - VoidCallback onCustom, | ||
120 | - Color cancelTextColor, | ||
121 | - Color confirmTextColor, | ||
122 | - String textConfirm, | ||
123 | - String textCancel, | ||
124 | - String textCustom, | ||
125 | - Widget confirm, | ||
126 | - Widget cancel, | ||
127 | - Widget custom, | ||
128 | - Color backgroundColor, | ||
129 | - Color buttonColor, | ||
130 | - String middleText = "Dialog made in 3 lines of code", | ||
131 | - double radius = 20.0, | ||
132 | - List<Widget> actions, | ||
133 | - }); | ||
134 | - | ||
135 | - Future<T> bottomSheet<T>( | ||
136 | - Widget bottomsheet, { | ||
137 | - Color backgroundColor, | ||
138 | - double elevation, | ||
139 | - ShapeBorder shape, | ||
140 | - Clip clipBehavior, | ||
141 | - Color barrierColor, | ||
142 | - bool ignoreSafeArea, | ||
143 | - bool isScrollControlled = false, | ||
144 | - bool useRootNavigator = false, | ||
145 | - bool isDismissible = true, | ||
146 | - bool enableDrag = true, | ||
147 | - }); | ||
148 | - | ||
149 | - void rawSnackbar( | ||
150 | - {String title, | ||
151 | - String message, | ||
152 | - Widget titleText, | ||
153 | - Widget messageText, | ||
154 | - Widget icon, | ||
155 | - bool instantInit = true, | ||
156 | - bool shouldIconPulse = true, | ||
157 | - double maxWidth, | ||
158 | - EdgeInsets margin = const EdgeInsets.all(0.0), | ||
159 | - EdgeInsets padding = const EdgeInsets.all(16), | ||
160 | - double borderRadius = 0.0, | ||
161 | - Color borderColor, | ||
162 | - double borderWidth = 1.0, | ||
163 | - Color backgroundColor = const Color(0xFF303030), | ||
164 | - Color leftBarIndicatorColor, | ||
165 | - List<BoxShadow> boxShadows, | ||
166 | - Gradient backgroundGradient, | ||
167 | - FlatButton mainButton, | ||
168 | - OnTap onTap, | ||
169 | - Duration duration = const Duration(seconds: 3), | ||
170 | - bool isDismissible = true, | ||
171 | - SnackDismissDirection dismissDirection = SnackDismissDirection.VERTICAL, | ||
172 | - bool showProgressIndicator = false, | ||
173 | - AnimationController progressIndicatorController, | ||
174 | - Color progressIndicatorBackgroundColor, | ||
175 | - Animation<Color> progressIndicatorValueColor, | ||
176 | - SnackPosition snackPosition = SnackPosition.BOTTOM, | ||
177 | - SnackStyle snackStyle = SnackStyle.FLOATING, | ||
178 | - Curve forwardAnimationCurve = Curves.easeOutCirc, | ||
179 | - Curve reverseAnimationCurve = Curves.easeOutCirc, | ||
180 | - Duration animationDuration = const Duration(seconds: 1), | ||
181 | - SnackStatusCallback onStatusChanged, | ||
182 | - double barBlur = 0.0, | ||
183 | - double overlayBlur = 0.0, | ||
184 | - Color overlayColor = Colors.transparent, | ||
185 | - Form userInputForm}); | ||
186 | - | ||
187 | - void snackbar(String title, String message, | ||
188 | - {Color colorText, | ||
189 | - Duration duration, | ||
190 | - | ||
191 | - /// with instantInit = false you can put Get.snackbar on initState | ||
192 | - bool instantInit = true, | ||
193 | - SnackPosition snackPosition, | ||
194 | - Widget titleText, | ||
195 | - Widget messageText, | ||
196 | - Widget icon, | ||
197 | - bool shouldIconPulse, | ||
198 | - double maxWidth, | ||
199 | - EdgeInsets margin, | ||
200 | - EdgeInsets padding, | ||
201 | - double borderRadius, | ||
202 | - Color borderColor, | ||
203 | - double borderWidth, | ||
204 | - Color backgroundColor, | ||
205 | - Color leftBarIndicatorColor, | ||
206 | - List<BoxShadow> boxShadows, | ||
207 | - Gradient backgroundGradient, | ||
208 | - FlatButton mainButton, | ||
209 | - OnTap onTap, | ||
210 | - bool isDismissible, | ||
211 | - bool showProgressIndicator, | ||
212 | - SnackDismissDirection dismissDirection, | ||
213 | - AnimationController progressIndicatorController, | ||
214 | - Color progressIndicatorBackgroundColor, | ||
215 | - Animation<Color> progressIndicatorValueColor, | ||
216 | - SnackStyle snackStyle, | ||
217 | - Curve forwardAnimationCurve, | ||
218 | - Curve reverseAnimationCurve, | ||
219 | - Duration animationDuration, | ||
220 | - double barBlur, | ||
221 | - double overlayBlur, | ||
222 | - Color overlayColor, | ||
223 | - Form userInputForm}); | ||
224 | - | ||
225 | - /// INSTANCE MANAGER | ||
226 | - | ||
227 | - GetMaterialController getxController; | ||
228 | - | ||
229 | - void changeTheme(ThemeData theme); | ||
230 | - | ||
231 | - void changeThemeMode(ThemeMode themeMode); | ||
232 | - | ||
233 | - GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey); | ||
234 | - | ||
235 | - GlobalKey<NavigatorState> key; | ||
236 | - | ||
237 | - GlobalKey<NavigatorState> nestedKey(int key); | ||
238 | - | ||
239 | - GlobalKey<NavigatorState> global(int k); | ||
240 | - //////////// INSTANCE MANAGER | ||
241 | - | ||
242 | - // setParameter(Map<String, String> param); | ||
243 | - | ||
244 | - /// give current arguments | ||
245 | - Object get arguments; | ||
246 | - | ||
247 | - /// give current arguments | ||
248 | - Map<String, String> get parameters; | ||
249 | - | ||
250 | - /// give name from current route | ||
251 | - String get currentRoute; | ||
252 | - | ||
253 | - /// give name from previous route | ||
254 | - String get previousRoute; | ||
255 | - | ||
256 | - /// check if snackbar is open | ||
257 | - bool get isSnackbarOpen; | ||
258 | - | ||
259 | - /// check if dialog is open | ||
260 | - bool get isDialogOpen; | ||
261 | - | ||
262 | - /// check if bottomsheet is open | ||
263 | - bool get isBottomSheetOpen; | ||
264 | - | ||
265 | - /// check a raw current route | ||
266 | - Route<dynamic> get rawRoute; | ||
267 | - | ||
268 | - /// give access to currentContext | ||
269 | - BuildContext get context; | ||
270 | - | ||
271 | - /// give access to current Overlay Context | ||
272 | - BuildContext get overlayContext; | ||
273 | - | ||
274 | - /// give access to Theme.of(context) | ||
275 | - ThemeData get theme; | ||
276 | - | ||
277 | - /// give access to TextTheme.of(context) | ||
278 | - TextTheme get textTheme; | ||
279 | - | ||
280 | - /// give access to Mediaquery.of(context) | ||
281 | - MediaQueryData get mediaQuery; | ||
282 | - | ||
283 | - /// Check if dark mode theme is enable | ||
284 | - bool get isDarkMode; | ||
285 | - | ||
286 | - /// Check if dark mode theme is enable on platform on android Q+ | ||
287 | - bool get isPlatformDarkMode; | ||
288 | - | ||
289 | - /// give access to Theme.of(context).iconTheme.color | ||
290 | - Color get iconColor; | ||
291 | - | ||
292 | - /// give access to Focus.of(context).iconTheme.color | ||
293 | - FocusNode get focusScope; | ||
294 | - | ||
295 | - /// give access to MediaQuery.of(context).size.height | ||
296 | - double get height; | ||
297 | - | ||
298 | - /// give access to MediaQuery.of(context).size.width | ||
299 | - double get width; | 41 | + Map<String, Map<String, String>> translations = {}; |
300 | } | 42 | } |
1 | -import 'package:flutter/material.dart'; | ||
2 | -import 'package:flutter/scheduler.dart'; | ||
3 | -import 'package:get/get.dart'; | ||
4 | -import 'package:get/src/instance/get_instance.dart'; | ||
5 | import 'package:get/src/get_interface.dart'; | 1 | import 'package:get/src/get_interface.dart'; |
6 | -import 'bottomsheet/bottomsheet.dart'; | ||
7 | -import 'instance/get_instance.dart'; | ||
8 | -import 'platform/platform.dart'; | ||
9 | -import 'root/parse_route.dart'; | ||
10 | -import 'root/root_controller.dart'; | ||
11 | -import 'routes/bindings_interface.dart'; | ||
12 | -import 'routes/default_route.dart'; | ||
13 | -import 'routes/observers/route_observer.dart'; | ||
14 | -import 'routes/transitions_type.dart'; | ||
15 | -import 'snackbar/snack.dart'; | ||
16 | 2 | ||
17 | ///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, | 3 | ///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, |
18 | ///offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | 4 | ///offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" |
@@ -20,933 +6,7 @@ import 'snackbar/snack.dart'; | @@ -20,933 +6,7 @@ import 'snackbar/snack.dart'; | ||
20 | ///To return to the previous screen, use back(). | 6 | ///To return to the previous screen, use back(). |
21 | ///No need to pass any context to Get, just put the name of the route inside | 7 | ///No need to pass any context to Get, just put the name of the route inside |
22 | ///the parentheses and the magic will occur. | 8 | ///the parentheses and the magic will occur. |
23 | -class GetImpl implements GetService { | ||
24 | - bool defaultPopGesture = GetPlatform.isIOS; | ||
25 | - bool defaultOpaqueRoute = true; | ||
26 | - Transition defaultTransition; | ||
27 | - Duration defaultDurationTransition = Duration(milliseconds: 400); | ||
28 | - bool defaultGlobalState = true; | ||
29 | - RouteSettings settings; | ||
30 | - String defaultSeparator = "_"; | ||
31 | - | ||
32 | - /// Pushes a new [page] to the stack | ||
33 | - /// | ||
34 | - /// It has the advantage of not needing context, | ||
35 | - /// so you can call from your business logic | ||
36 | - /// | ||
37 | - /// You can set a custom [transition], and a transition [duration]. | ||
38 | - /// | ||
39 | - /// You can send any type of value to the other route in the [arguments]. | ||
40 | - /// | ||
41 | - /// Just like native routing in Flutter, you can push a route | ||
42 | - /// as a [fullscreenDialog], | ||
43 | - /// | ||
44 | - /// [id] is for when you are using nested navigation, | ||
45 | - /// as explained in documentation | ||
46 | - /// | ||
47 | - /// If you want the same behavior of ios that pops a route when the user drag, | ||
48 | - /// you can set [popGesture] to true | ||
49 | - /// | ||
50 | - /// If you're using the [Bindings] api, you must define it here | ||
51 | - /// | ||
52 | - /// By default, GetX will prevent you from push a route that you already in, | ||
53 | - /// if you want to push anyway, set [preventDuplicates] to false | ||
54 | - Future<T> to<T>( | ||
55 | - Widget page, { | ||
56 | - bool opaque, | ||
57 | - Transition transition, | ||
58 | - Duration duration, | ||
59 | - int id, | ||
60 | - bool fullscreenDialog = false, | ||
61 | - Object arguments, | ||
62 | - Bindings binding, | ||
63 | - preventDuplicates = true, | ||
64 | - bool popGesture, | ||
65 | - }) { | ||
66 | - if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { | ||
67 | - return null; | ||
68 | - } | ||
69 | - | ||
70 | - return global(id).currentState.push( | ||
71 | - GetPageRoute( | ||
72 | - opaque: opaque ?? true, | ||
73 | - page: () => page, | ||
74 | - settings: RouteSettings( | ||
75 | - name: '/${page.runtimeType}', | ||
76 | - arguments: arguments, | ||
77 | - ), | ||
78 | - popGesture: popGesture ?? defaultPopGesture, | ||
79 | - transition: transition ?? defaultTransition, | ||
80 | - fullscreenDialog: fullscreenDialog, | ||
81 | - binding: binding, | ||
82 | - transitionDuration: duration ?? defaultDurationTransition, | ||
83 | - ), | ||
84 | - ); | ||
85 | - } | ||
86 | - | ||
87 | - /// Pushes a new named [page] to the stack | ||
88 | - /// | ||
89 | - /// It has the advantage of not needing context, so you can call | ||
90 | - /// from your business logic. | ||
91 | - /// | ||
92 | - /// You can send any type of value to the other route in the [arguments]. | ||
93 | - /// | ||
94 | - /// [id] is for when you are using nested navigation, | ||
95 | - /// as explained in documentation | ||
96 | - /// | ||
97 | - /// By default, GetX will prevent you from push a route that you already in, | ||
98 | - /// if you want to push anyway, set [preventDuplicates] to false | ||
99 | - /// | ||
100 | - /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
101 | - Future<T> toNamed<T>( | ||
102 | - String page, { | ||
103 | - Object arguments, | ||
104 | - int id, | ||
105 | - preventDuplicates = true, | ||
106 | - }) { | ||
107 | - if (preventDuplicates && page == currentRoute) { | ||
108 | - return null; | ||
109 | - } | ||
110 | - return global(id).currentState.pushNamed(page, arguments: arguments); | ||
111 | - } | ||
112 | - | ||
113 | - /// Pop the current named [page] in the stack and push a new one in its place | ||
114 | - /// | ||
115 | - /// It has the advantage of not needing context, so you can call | ||
116 | - /// from your business logic. | ||
117 | - /// | ||
118 | - /// You can send any type of value to the other route in the [arguments]. | ||
119 | - /// | ||
120 | - /// [id] is for when you are using nested navigation, | ||
121 | - /// as explained in documentation | ||
122 | - /// | ||
123 | - /// By default, GetX will prevent you from push a route that you already in, | ||
124 | - /// if you want to push anyway, set [preventDuplicates] to false | ||
125 | - /// | ||
126 | - /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
127 | - Future<T> offNamed<T>( | ||
128 | - String page, { | ||
129 | - Object arguments, | ||
130 | - int id, | ||
131 | - preventDuplicates = true, | ||
132 | - }) { | ||
133 | - if (preventDuplicates && page == currentRoute) { | ||
134 | - return null; | ||
135 | - } | ||
136 | - return global(id) | ||
137 | - .currentState | ||
138 | - .pushReplacementNamed(page, arguments: arguments); | ||
139 | - } | ||
140 | - | ||
141 | - /// Calls pop several times in the stack until [predicate] returns true | ||
142 | - /// | ||
143 | - /// [id] is for when you are using nested navigation, | ||
144 | - /// as explained in documentation | ||
145 | - /// | ||
146 | - /// [predicate] can be used like this: | ||
147 | - /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
148 | - /// | ||
149 | - /// or also like this: | ||
150 | - /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
151 | - void until(RoutePredicate predicate, {int id}) { | ||
152 | - // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
153 | - // when widget don't mounted | ||
154 | - return global(id).currentState.popUntil(predicate); | ||
155 | - } | ||
156 | - | ||
157 | - /// Push the given [page], and then pop several [pages] in the stack until | ||
158 | - /// [predicate] returns true | ||
159 | - /// | ||
160 | - /// [id] is for when you are using nested navigation, | ||
161 | - /// as explained in documentation | ||
162 | - /// | ||
163 | - /// [predicate] can be used like this: | ||
164 | - /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
165 | - /// | ||
166 | - /// or also like this: | ||
167 | - /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
168 | - Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { | ||
169 | - // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
170 | - // when widget don't mounted | ||
171 | - return global(id).currentState.pushAndRemoveUntil(page, predicate); | ||
172 | - } | ||
173 | - | ||
174 | - /// Push the given named [page], and then pop several pages in the stack | ||
175 | - /// until [predicate] returns true | ||
176 | - /// | ||
177 | - /// You can send any type of value to the other route in the [arguments]. | ||
178 | - /// | ||
179 | - /// [id] is for when you are using nested navigation, | ||
180 | - /// as explained in documentation | ||
181 | - /// | ||
182 | - /// [predicate] can be used like this: | ||
183 | - /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
184 | - /// or also like | ||
185 | - /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
186 | - /// | ||
187 | - /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
188 | - Future<T> offNamedUntil<T>( | ||
189 | - String page, | ||
190 | - RoutePredicate predicate, { | ||
191 | - int id, | ||
192 | - Object arguments, | ||
193 | - }) { | ||
194 | - return global(id) | ||
195 | - .currentState | ||
196 | - .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); | ||
197 | - } | ||
198 | - | ||
199 | - /// Pop the current named page and pushes a new [page] to the stack in its place | ||
200 | - /// | ||
201 | - /// You can send any type of value to the other route in the [arguments]. | ||
202 | - /// It is very similar to `offNamed()` but use a different approach | ||
203 | - /// | ||
204 | - /// The `offNamed()` pop a page, and goes to the next. The `offAndToNamed()` goes | ||
205 | - /// to the next page, and removes the previous one. The route transition | ||
206 | - /// animation is different. | ||
207 | - Future<T> offAndToNamed<T>(String page, | ||
208 | - {Object arguments, int id, dynamic result}) { | ||
209 | - return global(id) | ||
210 | - .currentState | ||
211 | - .popAndPushNamed(page, arguments: arguments, result: result); | ||
212 | - } | ||
213 | - | ||
214 | - /// Remove a specific [route] from the stack | ||
215 | - /// | ||
216 | - /// [id] is for when you are using nested navigation, | ||
217 | - /// as explained in documentation | ||
218 | - void removeRoute(Route<dynamic> route, {int id}) { | ||
219 | - return global(id).currentState.removeRoute(route); | ||
220 | - } | ||
221 | - | ||
222 | - /// Push a named [page] and remove all other pages from stack | ||
223 | - /// | ||
224 | - /// It has the advantage of not needing context, so you can | ||
225 | - /// call from your business logic. | ||
226 | - /// | ||
227 | - /// You can send any type of value to the other route in the [arguments]. | ||
228 | - /// | ||
229 | - /// [id] is for when you are using nested navigation, | ||
230 | - /// as explained in documentation | ||
231 | - /// | ||
232 | - /// Note: Always put a slash on the route ('/page1'), to avoid unexpected errors | ||
233 | - Future<T> offAllNamed<T>(String newRouteName, | ||
234 | - {RoutePredicate predicate, Object arguments, int id}) { | ||
235 | - var route = (Route<dynamic> rota) => false; | ||
236 | - | ||
237 | - return global(id).currentState.pushNamedAndRemoveUntil( | ||
238 | - newRouteName, predicate ?? route, | ||
239 | - arguments: arguments); | ||
240 | - } | ||
241 | - | ||
242 | - /// Returns true if a snackbar, dialog or bottomsheet is currently showing in the screen | ||
243 | - bool get isOverlaysOpen => | ||
244 | - (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); | ||
245 | - | ||
246 | - /// returns true if there is no snackbar, dialog or bottomsheet open | ||
247 | - bool get isOverlaysClosed => | ||
248 | - (!isSnackbarOpen && !isDialogOpen && !isBottomSheetOpen); | ||
249 | - | ||
250 | - /// Pop the current page, snackbar, dialog or bottomsheet in the stack | ||
251 | - /// | ||
252 | - /// if your set [closeOverlays] to true, Get.back() will close the currently open | ||
253 | - /// snackbar/dialog/bottomsheet AND the current page | ||
254 | - /// | ||
255 | - /// [id] is for when you are using nested navigation, | ||
256 | - /// as explained in documentation | ||
257 | - /// | ||
258 | - /// It has the advantage of not needing context, so you can call | ||
259 | - /// from your business logic. | ||
260 | - void back({ | ||
261 | - dynamic result, | ||
262 | - bool closeOverlays = false, | ||
263 | - bool canPop = true, | ||
264 | - int id, | ||
265 | - }) { | ||
266 | - if (closeOverlays && isOverlaysOpen) { | ||
267 | - navigator.popUntil((route) { | ||
268 | - return (isOverlaysClosed); | ||
269 | - }); | ||
270 | - } | ||
271 | - if (canPop) { | ||
272 | - if (global(id).currentState.canPop()) { | ||
273 | - global(id).currentState.pop(result); | ||
274 | - } | ||
275 | - } else { | ||
276 | - global(id).currentState.pop(result); | ||
277 | - } | ||
278 | - } | ||
279 | - | ||
280 | - /// Close as many routes as defined by [times] | ||
281 | - void close(int times, [int id]) { | ||
282 | - if ((times == null) || (times < 1)) { | ||
283 | - times = 1; | ||
284 | - } | ||
285 | - int count = 0; | ||
286 | - void back = global(id).currentState.popUntil((route) { | ||
287 | - return count++ == times; | ||
288 | - }); | ||
289 | - return back; | ||
290 | - } | ||
291 | - | ||
292 | - /// Pop the current page and pushes a new [page] to the stack | ||
293 | - /// | ||
294 | - /// It has the advantage of not needing context, | ||
295 | - /// so you can call from your business logic | ||
296 | - /// | ||
297 | - /// You can set a custom [transition], and a transition [duration]. | ||
298 | - /// | ||
299 | - /// You can send any type of value to the other route in the [arguments]. | ||
300 | - /// | ||
301 | - /// Just like native routing in Flutter, you can push a route | ||
302 | - /// as a [fullscreenDialog], | ||
303 | - /// | ||
304 | - /// [id] is for when you are using nested navigation, | ||
305 | - /// as explained in documentation | ||
306 | - /// | ||
307 | - /// If you want the same behavior of ios that pops a route when the user drag, | ||
308 | - /// you can set [popGesture] to true | ||
309 | - /// | ||
310 | - /// If you're using the [Bindings] api, you must define it here | ||
311 | - /// | ||
312 | - /// By default, GetX will prevent you from push a route that you already in, | ||
313 | - /// if you want to push anyway, set [preventDuplicates] to false | ||
314 | - Future<T> off<T>( | ||
315 | - Widget page, { | ||
316 | - bool opaque = false, | ||
317 | - Transition transition, | ||
318 | - bool popGesture, | ||
319 | - int id, | ||
320 | - Object arguments, | ||
321 | - Bindings binding, | ||
322 | - bool fullscreenDialog = false, | ||
323 | - preventDuplicates = true, | ||
324 | - Duration duration, | ||
325 | - }) { | ||
326 | - if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { | ||
327 | - return null; | ||
328 | - } | ||
329 | - return global(id).currentState.pushReplacement(GetPageRoute( | ||
330 | - opaque: opaque ?? true, | ||
331 | - page: () => page, | ||
332 | - binding: binding, | ||
333 | - settings: | ||
334 | - RouteSettings(name: '/${page.runtimeType}', arguments: arguments), | ||
335 | - fullscreenDialog: fullscreenDialog, | ||
336 | - popGesture: popGesture ?? defaultPopGesture, | ||
337 | - transition: transition ?? defaultTransition, | ||
338 | - transitionDuration: duration ?? defaultDurationTransition)); | ||
339 | - } | ||
340 | - | ||
341 | - /// Pop all pages in the stack and pushes a new [page] to it | ||
342 | - /// | ||
343 | - /// It has the advantage of not needing context, | ||
344 | - /// so you can call from your business logic | ||
345 | - /// | ||
346 | - /// You can set a custom [transition], and a transition [duration]. | ||
347 | - /// | ||
348 | - /// You can send any type of value to the other route in the [arguments]. | ||
349 | - /// | ||
350 | - /// Just like native routing in Flutter, you can push a route | ||
351 | - /// as a [fullscreenDialog], | ||
352 | - /// | ||
353 | - /// [predicate] can be used like this: | ||
354 | - /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
355 | - /// or also like | ||
356 | - /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
357 | - /// | ||
358 | - /// [id] is for when you are using nested navigation, | ||
359 | - /// as explained in documentation | ||
360 | - /// | ||
361 | - /// If you want the same behavior of ios that pops a route when the user drag, | ||
362 | - /// you can set [popGesture] to true | ||
363 | - /// | ||
364 | - /// If you're using the [Bindings] api, you must define it here | ||
365 | - /// | ||
366 | - /// By default, GetX will prevent you from push a route that you already in, | ||
367 | - /// if you want to push anyway, set [preventDuplicates] to false | ||
368 | - Future<T> offAll<T>( | ||
369 | - Widget page, { | ||
370 | - RoutePredicate predicate, | ||
371 | - bool opaque = false, | ||
372 | - bool popGesture, | ||
373 | - int id, | ||
374 | - Object arguments, | ||
375 | - Bindings binding, | ||
376 | - bool fullscreenDialog = false, | ||
377 | - Duration duration, | ||
378 | - Transition transition, | ||
379 | - }) { | ||
380 | - var route = (Route<dynamic> rota) => false; | ||
381 | - | ||
382 | - return global(id).currentState.pushAndRemoveUntil( | ||
383 | - GetPageRoute( | ||
384 | - opaque: opaque ?? true, | ||
385 | - popGesture: popGesture ?? defaultPopGesture, | ||
386 | - page: () => page, | ||
387 | - binding: binding, | ||
388 | - settings: | ||
389 | - RouteSettings(name: '/${page.runtimeType}', arguments: arguments), | ||
390 | - fullscreenDialog: fullscreenDialog, | ||
391 | - transition: transition ?? defaultTransition, | ||
392 | - transitionDuration: duration ?? defaultDurationTransition, | ||
393 | - ), | ||
394 | - predicate ?? route); | ||
395 | - } | ||
396 | - | ||
397 | - /// Show a dialog | ||
398 | - Future<T> dialog<T>( | ||
399 | - Widget child, { | ||
400 | - bool barrierDismissible = true, | ||
401 | - bool useRootNavigator = true, | ||
402 | - // RouteSettings routeSettings | ||
403 | - }) { | ||
404 | - return showDialog( | ||
405 | - barrierDismissible: barrierDismissible, | ||
406 | - useRootNavigator: useRootNavigator, | ||
407 | - routeSettings: RouteSettings(name: 'dialog'), | ||
408 | - context: overlayContext, | ||
409 | - builder: (_) { | ||
410 | - return child; | ||
411 | - }, | ||
412 | - ); | ||
413 | - } | ||
414 | - | ||
415 | - /// Api from showGeneralDialog with no context | ||
416 | - Future<T> generalDialog<T>({ | ||
417 | - @required RoutePageBuilder pageBuilder, | ||
418 | - String barrierLabel = "Dismiss", | ||
419 | - bool barrierDismissible = true, | ||
420 | - Color barrierColor = const Color(0x80000000), | ||
421 | - Duration transitionDuration = const Duration(milliseconds: 200), | ||
422 | - RouteTransitionsBuilder transitionBuilder, | ||
423 | - bool useRootNavigator = true, | ||
424 | - RouteSettings routeSettings, | ||
425 | - }) { | ||
426 | - return showGeneralDialog( | ||
427 | - pageBuilder: pageBuilder, | ||
428 | - barrierDismissible: barrierDismissible, | ||
429 | - barrierLabel: barrierLabel, | ||
430 | - barrierColor: barrierColor, | ||
431 | - transitionDuration: transitionDuration, | ||
432 | - transitionBuilder: transitionBuilder, | ||
433 | - useRootNavigator: useRootNavigator, | ||
434 | - routeSettings: RouteSettings(name: 'dialog'), | ||
435 | - context: overlayContext, | ||
436 | - ); | ||
437 | - } | ||
438 | - | ||
439 | - Future<T> defaultDialog<T>({ | ||
440 | - String title = "Alert", | ||
441 | - Widget content, | ||
442 | - VoidCallback onConfirm, | ||
443 | - VoidCallback onCancel, | ||
444 | - VoidCallback onCustom, | ||
445 | - Color cancelTextColor, | ||
446 | - Color confirmTextColor, | ||
447 | - String textConfirm, | ||
448 | - String textCancel, | ||
449 | - String textCustom, | ||
450 | - Widget confirm, | ||
451 | - Widget cancel, | ||
452 | - Widget custom, | ||
453 | - Color backgroundColor, | ||
454 | - Color buttonColor, | ||
455 | - String middleText = "Dialog made in 3 lines of code", | ||
456 | - double radius = 20.0, | ||
457 | - List<Widget> actions, | ||
458 | - }) { | ||
459 | - bool leanCancel = onCancel != null || textCancel != null; | ||
460 | - bool leanConfirm = onConfirm != null || textConfirm != null; | ||
461 | - actions ??= []; | ||
462 | - | ||
463 | - if (cancel != null) { | ||
464 | - actions.add(cancel); | ||
465 | - } else { | ||
466 | - if (leanCancel) { | ||
467 | - actions.add(FlatButton( | ||
468 | - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | ||
469 | - onPressed: () { | ||
470 | - onCancel?.call(); | ||
471 | - back(); | ||
472 | - }, | ||
473 | - padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8), | ||
474 | - child: Text( | ||
475 | - textCancel ?? "Cancel", | ||
476 | - style: TextStyle(color: cancelTextColor ?? theme.accentColor), | ||
477 | - ), | ||
478 | - shape: RoundedRectangleBorder( | ||
479 | - side: BorderSide( | ||
480 | - color: buttonColor ?? theme.accentColor, | ||
481 | - width: 2, | ||
482 | - style: BorderStyle.solid), | ||
483 | - borderRadius: BorderRadius.circular(100)), | ||
484 | - )); | ||
485 | - } | ||
486 | - } | ||
487 | - if (confirm != null) { | ||
488 | - actions.add(confirm); | ||
489 | - } else { | ||
490 | - if (leanConfirm) { | ||
491 | - actions.add(FlatButton( | ||
492 | - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | ||
493 | - color: buttonColor ?? theme.accentColor, | ||
494 | - shape: RoundedRectangleBorder( | ||
495 | - borderRadius: BorderRadius.circular(100)), | ||
496 | - child: Text( | ||
497 | - textConfirm ?? "Ok", | ||
498 | - style: TextStyle(color: confirmTextColor ?? theme.primaryColor), | ||
499 | - ), | ||
500 | - onPressed: () { | ||
501 | - onConfirm?.call(); | ||
502 | - })); | ||
503 | - } | ||
504 | - } | ||
505 | - return dialog(AlertDialog( | ||
506 | - titlePadding: EdgeInsets.all(8), | ||
507 | - contentPadding: EdgeInsets.all(8), | ||
508 | - backgroundColor: backgroundColor ?? theme.dialogBackgroundColor, | ||
509 | - shape: RoundedRectangleBorder( | ||
510 | - borderRadius: BorderRadius.all(Radius.circular(radius))), | ||
511 | - title: Text(title, textAlign: TextAlign.center), | ||
512 | - content: Column( | ||
513 | - crossAxisAlignment: CrossAxisAlignment.center, | ||
514 | - mainAxisSize: MainAxisSize.min, | ||
515 | - children: [ | ||
516 | - content ?? Text(middleText ?? "", textAlign: TextAlign.center), | ||
517 | - SizedBox(height: 16), | ||
518 | - ButtonTheme( | ||
519 | - minWidth: 78.0, | ||
520 | - height: 34.0, | ||
521 | - child: Wrap( | ||
522 | - alignment: WrapAlignment.center, | ||
523 | - spacing: 8, | ||
524 | - runSpacing: 8, | ||
525 | - children: actions, | ||
526 | - ), | ||
527 | - ) | ||
528 | - ], | ||
529 | - ), | ||
530 | - // actions: actions, // ?? <Widget>[cancelButton, confirmButton], | ||
531 | - buttonPadding: EdgeInsets.zero, | ||
532 | - )); | ||
533 | - } | ||
534 | - | ||
535 | - Future<T> bottomSheet<T>( | ||
536 | - Widget bottomsheet, { | ||
537 | - Color backgroundColor, | ||
538 | - double elevation, | ||
539 | - ShapeBorder shape, | ||
540 | - Clip clipBehavior, | ||
541 | - Color barrierColor, | ||
542 | - bool ignoreSafeArea, | ||
543 | - bool isScrollControlled = false, | ||
544 | - bool useRootNavigator = false, | ||
545 | - bool isDismissible = true, | ||
546 | - bool enableDrag = true, | ||
547 | - }) { | ||
548 | - assert(bottomsheet != null); | ||
549 | - assert(isScrollControlled != null); | ||
550 | - assert(useRootNavigator != null); | ||
551 | - assert(isDismissible != null); | ||
552 | - assert(enableDrag != null); | ||
553 | - | ||
554 | - return Navigator.of(overlayContext, rootNavigator: useRootNavigator) | ||
555 | - .push(GetModalBottomSheetRoute<T>( | ||
556 | - builder: (_) => bottomsheet, | ||
557 | - theme: Theme.of(key.currentContext, shadowThemeOnly: true), | ||
558 | - isScrollControlled: isScrollControlled, | ||
559 | - barrierLabel: | ||
560 | - MaterialLocalizations.of(key.currentContext).modalBarrierDismissLabel, | ||
561 | - backgroundColor: backgroundColor ?? Colors.transparent, | ||
562 | - elevation: elevation, | ||
563 | - shape: shape, | ||
564 | - removeTop: ignoreSafeArea ?? true, | ||
565 | - clipBehavior: clipBehavior, | ||
566 | - isDismissible: isDismissible, | ||
567 | - modalBarrierColor: barrierColor, | ||
568 | - settings: RouteSettings(name: "bottomsheet"), | ||
569 | - enableDrag: enableDrag, | ||
570 | - )); | ||
571 | - } | ||
572 | - | ||
573 | - void rawSnackbar( | ||
574 | - {String title, | ||
575 | - String message, | ||
576 | - Widget titleText, | ||
577 | - Widget messageText, | ||
578 | - Widget icon, | ||
579 | - bool instantInit = true, | ||
580 | - bool shouldIconPulse = true, | ||
581 | - double maxWidth, | ||
582 | - EdgeInsets margin = const EdgeInsets.all(0.0), | ||
583 | - EdgeInsets padding = const EdgeInsets.all(16), | ||
584 | - double borderRadius = 0.0, | ||
585 | - Color borderColor, | ||
586 | - double borderWidth = 1.0, | ||
587 | - Color backgroundColor = const Color(0xFF303030), | ||
588 | - Color leftBarIndicatorColor, | ||
589 | - List<BoxShadow> boxShadows, | ||
590 | - Gradient backgroundGradient, | ||
591 | - FlatButton mainButton, | ||
592 | - OnTap onTap, | ||
593 | - Duration duration = const Duration(seconds: 3), | ||
594 | - bool isDismissible = true, | ||
595 | - SnackDismissDirection dismissDirection = SnackDismissDirection.VERTICAL, | ||
596 | - bool showProgressIndicator = false, | ||
597 | - AnimationController progressIndicatorController, | ||
598 | - Color progressIndicatorBackgroundColor, | ||
599 | - Animation<Color> progressIndicatorValueColor, | ||
600 | - SnackPosition snackPosition = SnackPosition.BOTTOM, | ||
601 | - SnackStyle snackStyle = SnackStyle.FLOATING, | ||
602 | - Curve forwardAnimationCurve = Curves.easeOutCirc, | ||
603 | - Curve reverseAnimationCurve = Curves.easeOutCirc, | ||
604 | - Duration animationDuration = const Duration(seconds: 1), | ||
605 | - SnackStatusCallback onStatusChanged, | ||
606 | - double barBlur = 0.0, | ||
607 | - double overlayBlur = 0.0, | ||
608 | - Color overlayColor = Colors.transparent, | ||
609 | - Form userInputForm}) { | ||
610 | - GetBar getBar = GetBar( | ||
611 | - title: title, | ||
612 | - message: message, | ||
613 | - titleText: titleText, | ||
614 | - messageText: messageText, | ||
615 | - snackPosition: snackPosition, | ||
616 | - borderRadius: borderRadius, | ||
617 | - margin: margin, | ||
618 | - duration: duration, | ||
619 | - barBlur: barBlur, | ||
620 | - backgroundColor: backgroundColor, | ||
621 | - icon: icon, | ||
622 | - shouldIconPulse: shouldIconPulse, | ||
623 | - maxWidth: maxWidth, | ||
624 | - padding: padding, | ||
625 | - borderColor: borderColor, | ||
626 | - borderWidth: borderWidth, | ||
627 | - leftBarIndicatorColor: leftBarIndicatorColor, | ||
628 | - boxShadows: boxShadows, | ||
629 | - backgroundGradient: backgroundGradient, | ||
630 | - mainButton: mainButton, | ||
631 | - onTap: onTap, | ||
632 | - isDismissible: isDismissible, | ||
633 | - dismissDirection: dismissDirection, | ||
634 | - showProgressIndicator: showProgressIndicator ?? false, | ||
635 | - progressIndicatorController: progressIndicatorController, | ||
636 | - progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, | ||
637 | - progressIndicatorValueColor: progressIndicatorValueColor, | ||
638 | - snackStyle: snackStyle, | ||
639 | - forwardAnimationCurve: forwardAnimationCurve, | ||
640 | - reverseAnimationCurve: reverseAnimationCurve, | ||
641 | - animationDuration: animationDuration, | ||
642 | - overlayBlur: overlayBlur, | ||
643 | - overlayColor: overlayColor, | ||
644 | - userInputForm: userInputForm); | ||
645 | - | ||
646 | - if (instantInit) { | ||
647 | - getBar.show(); | ||
648 | - } else { | ||
649 | - SchedulerBinding.instance.addPostFrameCallback((_) { | ||
650 | - getBar.show(); | ||
651 | - }); | ||
652 | - } | ||
653 | - } | ||
654 | - | ||
655 | - void snackbar(String title, String message, | ||
656 | - {Color colorText, | ||
657 | - Duration duration, | ||
658 | - | ||
659 | - /// with instantInit = false you can put snackbar on initState | ||
660 | - bool instantInit = true, | ||
661 | - SnackPosition snackPosition, | ||
662 | - Widget titleText, | ||
663 | - Widget messageText, | ||
664 | - Widget icon, | ||
665 | - bool shouldIconPulse, | ||
666 | - double maxWidth, | ||
667 | - EdgeInsets margin, | ||
668 | - EdgeInsets padding, | ||
669 | - double borderRadius, | ||
670 | - Color borderColor, | ||
671 | - double borderWidth, | ||
672 | - Color backgroundColor, | ||
673 | - Color leftBarIndicatorColor, | ||
674 | - List<BoxShadow> boxShadows, | ||
675 | - Gradient backgroundGradient, | ||
676 | - FlatButton mainButton, | ||
677 | - OnTap onTap, | ||
678 | - bool isDismissible, | ||
679 | - bool showProgressIndicator, | ||
680 | - SnackDismissDirection dismissDirection, | ||
681 | - AnimationController progressIndicatorController, | ||
682 | - Color progressIndicatorBackgroundColor, | ||
683 | - Animation<Color> progressIndicatorValueColor, | ||
684 | - SnackStyle snackStyle, | ||
685 | - Curve forwardAnimationCurve, | ||
686 | - Curve reverseAnimationCurve, | ||
687 | - Duration animationDuration, | ||
688 | - double barBlur, | ||
689 | - double overlayBlur, | ||
690 | - Color overlayColor, | ||
691 | - Form userInputForm}) { | ||
692 | - GetBar getBar = GetBar( | ||
693 | - titleText: (title == null) | ||
694 | - ? null | ||
695 | - : titleText ?? | ||
696 | - Text( | ||
697 | - title, | ||
698 | - style: TextStyle( | ||
699 | - color: colorText ?? theme.iconTheme.color, | ||
700 | - fontWeight: FontWeight.w800, | ||
701 | - fontSize: 16), | ||
702 | - ), | ||
703 | - messageText: messageText ?? | ||
704 | - Text( | ||
705 | - message, | ||
706 | - style: TextStyle( | ||
707 | - color: colorText ?? theme.iconTheme.color, | ||
708 | - fontWeight: FontWeight.w300, | ||
709 | - fontSize: 14), | ||
710 | - ), | ||
711 | - snackPosition: snackPosition ?? SnackPosition.TOP, | ||
712 | - borderRadius: borderRadius ?? 15, | ||
713 | - margin: margin ?? EdgeInsets.symmetric(horizontal: 10), | ||
714 | - duration: duration ?? Duration(seconds: 3), | ||
715 | - barBlur: barBlur ?? 7.0, | ||
716 | - backgroundColor: backgroundColor ?? Colors.grey.withOpacity(0.2), | ||
717 | - icon: icon, | ||
718 | - shouldIconPulse: shouldIconPulse ?? true, | ||
719 | - maxWidth: maxWidth, | ||
720 | - padding: padding ?? EdgeInsets.all(16), | ||
721 | - borderColor: borderColor, | ||
722 | - borderWidth: borderWidth, | ||
723 | - leftBarIndicatorColor: leftBarIndicatorColor, | ||
724 | - boxShadows: boxShadows, | ||
725 | - backgroundGradient: backgroundGradient, | ||
726 | - mainButton: mainButton, | ||
727 | - onTap: onTap, | ||
728 | - isDismissible: isDismissible ?? true, | ||
729 | - dismissDirection: dismissDirection ?? SnackDismissDirection.VERTICAL, | ||
730 | - showProgressIndicator: showProgressIndicator ?? false, | ||
731 | - progressIndicatorController: progressIndicatorController, | ||
732 | - progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, | ||
733 | - progressIndicatorValueColor: progressIndicatorValueColor, | ||
734 | - snackStyle: snackStyle ?? SnackStyle.FLOATING, | ||
735 | - forwardAnimationCurve: forwardAnimationCurve ?? Curves.easeOutCirc, | ||
736 | - reverseAnimationCurve: reverseAnimationCurve ?? Curves.easeOutCirc, | ||
737 | - animationDuration: animationDuration ?? Duration(seconds: 1), | ||
738 | - overlayBlur: overlayBlur ?? 0.0, | ||
739 | - overlayColor: overlayColor ?? Colors.transparent, | ||
740 | - userInputForm: userInputForm); | ||
741 | - | ||
742 | - if (instantInit) { | ||
743 | - getBar.show(); | ||
744 | - } else { | ||
745 | - _routing.isSnackbar = true; | ||
746 | - SchedulerBinding.instance.addPostFrameCallback((_) { | ||
747 | - getBar.show(); | ||
748 | - }); | ||
749 | - } | ||
750 | - } | ||
751 | - | ||
752 | - ParseRouteTree routeTree; | ||
753 | - | ||
754 | - void addPages(List<GetPage> getPages) { | ||
755 | - if (getPages != null) { | ||
756 | - if (routeTree == null) routeTree = ParseRouteTree(); | ||
757 | - getPages.forEach((element) { | ||
758 | - routeTree.addRoute(element); | ||
759 | - }); | ||
760 | - } | ||
761 | - } | ||
762 | - | ||
763 | - void addPage(GetPage getPage) { | ||
764 | - if (getPage != null) { | ||
765 | - if (routeTree == null) routeTree = ParseRouteTree(); | ||
766 | - routeTree.addRoute(getPage); | ||
767 | - } | ||
768 | - } | ||
769 | - | ||
770 | - /// change default config of Get | ||
771 | - void config( | ||
772 | - {bool enableLog, | ||
773 | - bool defaultPopGesture, | ||
774 | - bool defaultOpaqueRoute, | ||
775 | - Duration defaultDurationTransition, | ||
776 | - bool defaultGlobalState, | ||
777 | - Transition defaultTransition}) { | ||
778 | - if (enableLog != null) { | ||
779 | - GetConfig.isLogEnable = enableLog; | ||
780 | - } | ||
781 | - if (defaultPopGesture != null) { | ||
782 | - this.defaultPopGesture = defaultPopGesture; | ||
783 | - } | ||
784 | - if (defaultOpaqueRoute != null) { | ||
785 | - this.defaultOpaqueRoute = defaultOpaqueRoute; | ||
786 | - } | ||
787 | - if (defaultTransition != null) { | ||
788 | - this.defaultTransition = defaultTransition; | ||
789 | - } | ||
790 | - | ||
791 | - if (defaultDurationTransition != null) { | ||
792 | - this.defaultDurationTransition = defaultDurationTransition; | ||
793 | - } | ||
794 | - | ||
795 | - if (defaultGlobalState != null) { | ||
796 | - this.defaultGlobalState = defaultGlobalState; | ||
797 | - } | ||
798 | - } | ||
799 | - | ||
800 | - CustomTransition customTransition; | ||
801 | - | ||
802 | - GetMaterialController getxController = GetMaterialController(); | ||
803 | - | ||
804 | - Locale locale; | ||
805 | - | ||
806 | - void updateLocale(Locale l) { | ||
807 | - locale = l; | ||
808 | - forceAppUpdate(); | ||
809 | - } | ||
810 | - | ||
811 | - void forceAppUpdate() { | ||
812 | - void rebuild(Element el) { | ||
813 | - el.markNeedsBuild(); | ||
814 | - el.visitChildren(rebuild); | ||
815 | - } | ||
816 | - | ||
817 | - (context as Element).visitChildren(rebuild); | ||
818 | - } | ||
819 | - | ||
820 | - Map<String, Map<String, String>> translations = {}; | ||
821 | - | ||
822 | - void addTranslations(Map<String, Map<String, String>> tr) { | ||
823 | - translations.addAll(tr); | ||
824 | - } | ||
825 | - | ||
826 | - void appendTranslations(Map<String, Map<String, String>> tr) { | ||
827 | - tr.forEach((key, map) { | ||
828 | - if (Get.translations.containsKey(key)) { | ||
829 | - Get.translations[key].addAll(map); | ||
830 | - } else { | ||
831 | - Get.translations[key] = map; | ||
832 | - } | ||
833 | - }); | ||
834 | - } | ||
835 | - | ||
836 | - void changeTheme(ThemeData theme) { | ||
837 | - getxController.setTheme(theme); | ||
838 | - } | ||
839 | - | ||
840 | - void changeThemeMode(ThemeMode themeMode) { | ||
841 | - getxController.setThemeMode(themeMode); | ||
842 | - } | ||
843 | - | ||
844 | - GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { | ||
845 | - key = newKey; | ||
846 | - return key; | ||
847 | - } | ||
848 | - | ||
849 | - GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); | ||
850 | - | ||
851 | - Map<int, GlobalKey<NavigatorState>> _keys = {}; | ||
852 | - | ||
853 | - GlobalKey<NavigatorState> nestedKey(int key) { | ||
854 | - _keys.putIfAbsent(key, () => GlobalKey<NavigatorState>()); | ||
855 | - return _keys[key]; | ||
856 | - } | ||
857 | - | ||
858 | - GlobalKey<NavigatorState> global(int k) { | ||
859 | - if (k == null) { | ||
860 | - return key; | ||
861 | - } | ||
862 | - if (!_keys.containsKey(k)) { | ||
863 | - throw 'route id not found'; | ||
864 | - } | ||
865 | - return _keys[k]; | ||
866 | - } | ||
867 | - | ||
868 | - /// give access to Routing API from GetObserver | ||
869 | - Routing get routing => _routing; | ||
870 | - | ||
871 | - RouteSettings get routeSettings => settings; | ||
872 | - | ||
873 | - final _routing = Routing(); | ||
874 | - | ||
875 | - Map<String, String> parameters = {}; | ||
876 | - | ||
877 | - // void setRouting(Routing rt) { | ||
878 | - // _routing = rt; | ||
879 | - // } | ||
880 | - | ||
881 | - void setSettings(RouteSettings settings) { | ||
882 | - settings = settings; | ||
883 | - } | ||
884 | - | ||
885 | - /// give current arguments | ||
886 | - Object get arguments => _routing.args; | ||
887 | - | ||
888 | - /// give name from current route | ||
889 | - String get currentRoute => _routing.current; | ||
890 | - | ||
891 | - /// give name from previous route | ||
892 | - String get previousRoute => _routing.previous; | ||
893 | - | ||
894 | - /// check if snackbar is open | ||
895 | - bool get isSnackbarOpen => _routing.isSnackbar; | ||
896 | - | ||
897 | - /// check if dialog is open | ||
898 | - bool get isDialogOpen => _routing.isDialog; | ||
899 | - | ||
900 | - /// check if bottomsheet is open | ||
901 | - bool get isBottomSheetOpen => _routing.isBottomSheet; | ||
902 | - | ||
903 | - /// check a raw current route | ||
904 | - Route<dynamic> get rawRoute => _routing.route; | ||
905 | - | ||
906 | - /// check if popGesture is enable | ||
907 | - bool get isPopGestureEnable => defaultPopGesture; | ||
908 | - | ||
909 | - /// check if default opaque route is enable | ||
910 | - bool get isOpaqueRouteDefault => defaultOpaqueRoute; | ||
911 | - | ||
912 | - /// give access to currentContext | ||
913 | - BuildContext get context => key.currentContext; | ||
914 | - | ||
915 | - /// give access to current Overlay Context | ||
916 | - BuildContext get overlayContext => key.currentState.overlay.context; | ||
917 | - | ||
918 | - /// give access to Theme.of(context) | ||
919 | - ThemeData get theme => Theme.of(context); | ||
920 | - | ||
921 | - /// give access to TextTheme.of(context) | ||
922 | - TextTheme get textTheme => Theme.of(context).textTheme; | ||
923 | - | ||
924 | - /// give access to Mediaquery.of(context) | ||
925 | - MediaQueryData get mediaQuery => MediaQuery.of(context); | ||
926 | - | ||
927 | - /// Check if dark mode theme is enable | ||
928 | - bool get isDarkMode => (theme.brightness == Brightness.dark); | ||
929 | - | ||
930 | - /// Check if dark mode theme is enable on platform on android Q+ | ||
931 | - bool get isPlatformDarkMode => | ||
932 | - (mediaQuery.platformBrightness == Brightness.dark); | ||
933 | - | ||
934 | - /// give access to Theme.of(context).iconTheme.color | ||
935 | - Color get iconColor => Theme.of(context).iconTheme.color; | ||
936 | - | ||
937 | - /// give access to FocusScope.of(context) | ||
938 | - FocusNode get focusScope => FocusManager.instance.primaryFocus; | ||
939 | - | ||
940 | - /// give access to Immutable MediaQuery.of(context).size.height | ||
941 | - double get height => MediaQuery.of(context).size.height; | ||
942 | - | ||
943 | - /// give access to Immutable MediaQuery.of(context).size.width | ||
944 | - double get width => MediaQuery.of(context).size.width; | ||
945 | -} | 9 | +class _GetImpl extends GetInterface {} |
946 | 10 | ||
947 | // ignore: non_constant_identifier_names | 11 | // ignore: non_constant_identifier_names |
948 | -final Get = GetImpl(); | ||
949 | - | ||
950 | -/// It replaces the Flutter Navigator, but needs no context. | ||
951 | -/// You can to use navigator.push(YourRoute()) rather Navigator.push(context, YourRoute()); | ||
952 | -NavigatorState get navigator => Get.key.currentState; | 12 | +final Get = _GetImpl(); |
1 | -import 'package:get/src/typedefs/typedefs.dart'; | ||
2 | -import '../get_main.dart'; | 1 | +import 'package:get/src/get_interface.dart'; |
3 | import 'get_instance.dart'; | 2 | import 'get_instance.dart'; |
4 | 3 | ||
5 | -extension Inst on GetImpl { | 4 | +extension Inst on GetInterface { |
6 | void lazyPut<S>(FcBuilderFunc builder, {String tag, bool fenix = false}) { | 5 | void lazyPut<S>(FcBuilderFunc builder, {String tag, bool fenix = false}) { |
7 | return GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); | 6 | return GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); |
8 | } | 7 | } |
@@ -19,15 +18,9 @@ extension Inst on GetImpl { | @@ -19,15 +18,9 @@ extension Inst on GetImpl { | ||
19 | GetInstance().find<S>(tag: tag, instance: instance); | 18 | GetInstance().find<S>(tag: tag, instance: instance); |
20 | 19 | ||
21 | S put<S>(S dependency, | 20 | S put<S>(S dependency, |
22 | - {String tag, | ||
23 | - bool permanent = false, | ||
24 | - bool overrideAbstract = false, | ||
25 | - FcBuilderFunc<S> builder}) => | ||
26 | - GetInstance().put<S>(dependency, | ||
27 | - tag: tag, | ||
28 | - permanent: permanent, | ||
29 | - overrideAbstract: overrideAbstract, | ||
30 | - builder: builder); | 21 | + {String tag, bool permanent = false, FcBuilderFunc<S> builder}) => |
22 | + GetInstance() | ||
23 | + .put<S>(dependency, tag: tag, permanent: permanent, builder: builder); | ||
31 | 24 | ||
32 | bool reset({bool clearFactory = true, bool clearRouteBindings = true}) => | 25 | bool reset({bool clearFactory = true, bool clearRouteBindings = true}) => |
33 | GetInstance().reset( | 26 | GetInstance().reset( |
1 | -import 'package:get/src/root/smart_management.dart'; | ||
2 | -import 'package:get/src/rx/rx_interface.dart'; | ||
3 | -import 'package:get/src/typedefs/typedefs.dart'; | 1 | +import 'package:get/src/navigation/root/smart_management.dart'; |
2 | +import 'package:get/src/state_manager/rx/rx_interface.dart'; | ||
4 | 3 | ||
5 | class GetConfig { | 4 | class GetConfig { |
6 | //////////// INSTANCE MANAGER | 5 | //////////// INSTANCE MANAGER |
@@ -23,7 +22,7 @@ class GetInstance { | @@ -23,7 +22,7 @@ class GetInstance { | ||
23 | if (_getInstance == null) _getInstance = GetInstance._(); | 22 | if (_getInstance == null) _getInstance = GetInstance._(); |
24 | return _getInstance; | 23 | return _getInstance; |
25 | } | 24 | } |
26 | - GetInstance._(); | 25 | + const GetInstance._(); |
27 | static GetInstance _getInstance; | 26 | static GetInstance _getInstance; |
28 | 27 | ||
29 | void lazyPut<S>(FcBuilderFunc builder, {String tag, bool fenix = false}) { | 28 | void lazyPut<S>(FcBuilderFunc builder, {String tag, bool fenix = false}) { |
@@ -42,13 +41,10 @@ class GetInstance { | @@ -42,13 +41,10 @@ class GetInstance { | ||
42 | S dependency, { | 41 | S dependency, { |
43 | String tag, | 42 | String tag, |
44 | bool permanent = false, | 43 | bool permanent = false, |
45 | - bool overrideAbstract = false, | ||
46 | FcBuilderFunc<S> builder, | 44 | FcBuilderFunc<S> builder, |
47 | }) { | 45 | }) { |
48 | _insert( | 46 | _insert( |
49 | isSingleton: true, | 47 | isSingleton: true, |
50 | - replace: overrideAbstract, | ||
51 | - //?? (("$S" == "${dependency.runtimeType}") == false), | ||
52 | name: tag, | 48 | name: tag, |
53 | permanent: permanent, | 49 | permanent: permanent, |
54 | builder: builder ?? (() => dependency)); | 50 | builder: builder ?? (() => dependency)); |
@@ -73,18 +69,14 @@ class GetInstance { | @@ -73,18 +69,14 @@ class GetInstance { | ||
73 | void _insert<S>({ | 69 | void _insert<S>({ |
74 | bool isSingleton, | 70 | bool isSingleton, |
75 | String name, | 71 | String name, |
76 | - bool replace = true, | ||
77 | bool permanent = false, | 72 | bool permanent = false, |
78 | FcBuilderFunc<S> builder, | 73 | FcBuilderFunc<S> builder, |
79 | }) { | 74 | }) { |
80 | assert(builder != null); | 75 | assert(builder != null); |
81 | String key = _getKey(S, name); | 76 | String key = _getKey(S, name); |
82 | - if (replace) { | ||
83 | - GetConfig._singl[key] = FcBuilder<S>(isSingleton, builder, permanent); | ||
84 | - } else { | ||
85 | - GetConfig._singl.putIfAbsent( | ||
86 | - key, () => FcBuilder<S>(isSingleton, builder, permanent)); | ||
87 | - } | 77 | + |
78 | + GetConfig._singl | ||
79 | + .putIfAbsent(key, () => FcBuilder<S>(isSingleton, builder, permanent)); | ||
88 | } | 80 | } |
89 | 81 | ||
90 | void removeDependencyByRoute(String routeName) async { | 82 | void removeDependencyByRoute(String routeName) async { |
@@ -104,10 +96,6 @@ class GetInstance { | @@ -104,10 +96,6 @@ class GetInstance { | ||
104 | keysToRemove.clear(); | 96 | keysToRemove.clear(); |
105 | } | 97 | } |
106 | 98 | ||
107 | - bool isRouteDependecyNull<S>({String name}) { | ||
108 | - return (GetConfig.routesKey[_getKey(S, name)] == null); | ||
109 | - } | ||
110 | - | ||
111 | bool isDependencyInit<S>({String name}) { | 99 | bool isDependencyInit<S>({String name}) { |
112 | String key = _getKey(S, name); | 100 | String key = _getKey(S, name); |
113 | return GetConfig.routesKey.containsKey(key); | 101 | return GetConfig.routesKey.containsKey(key); |
@@ -133,6 +121,27 @@ class GetInstance { | @@ -133,6 +121,27 @@ class GetInstance { | ||
133 | } | 121 | } |
134 | } | 122 | } |
135 | 123 | ||
124 | + // S putOrFind<S>(S Function() dep, {String tag}) { | ||
125 | + // final key = _getKey(S, tag); | ||
126 | + | ||
127 | + // if (GetConfig._singl.containsKey(key)) { | ||
128 | + // return GetConfig._singl[key].getSependency() as S; | ||
129 | + // } else { | ||
130 | + // if (GetConfig._factory.containsKey(key)) { | ||
131 | + // S _value = put<S>((GetConfig._factory[key].builder() as S), tag: tag); | ||
132 | + | ||
133 | + // if (GetConfig.smartManagement != SmartManagement.keepFactory) { | ||
134 | + // if (!GetConfig._factory[key].fenix) { | ||
135 | + // GetConfig._factory.remove(key); | ||
136 | + // } | ||
137 | + // } | ||
138 | + // return _value; | ||
139 | + // } | ||
140 | + | ||
141 | + // return GetInstance().put(dep(), tag: tag); | ||
142 | + // } | ||
143 | + // } | ||
144 | + | ||
136 | /// Find a instance from required class | 145 | /// Find a instance from required class |
137 | S find<S>({String tag, FcBuilderFunc<S> instance}) { | 146 | S find<S>({String tag, FcBuilderFunc<S> instance}) { |
138 | String key = _getKey(S, tag); | 147 | String key = _getKey(S, tag); |
@@ -184,24 +193,6 @@ class GetInstance { | @@ -184,24 +193,6 @@ class GetInstance { | ||
184 | } | 193 | } |
185 | } | 194 | } |
186 | 195 | ||
187 | - /// Remove dependency of [S] on dependency abstraction. For concrete class use delete | ||
188 | - void remove<S>({String tag}) { | ||
189 | - String key = _getKey(S, tag); | ||
190 | - FcBuilder builder = GetConfig._singl[key] as FcBuilder; | ||
191 | - final i = builder.dependency; | ||
192 | - | ||
193 | - if (i is DisposableInterface) { | ||
194 | - i.onClose(); | ||
195 | - if (GetConfig.isLogEnable) print('[GETX] onClose of $key called'); | ||
196 | - } | ||
197 | - if (builder != null) builder.dependency = null; | ||
198 | - if (GetConfig._singl.containsKey(key)) { | ||
199 | - print('error on remove $key'); | ||
200 | - } else { | ||
201 | - if (GetConfig.isLogEnable) print('[GETX] $key removed from memory'); | ||
202 | - } | ||
203 | - } | ||
204 | - | ||
205 | String _getKey(Type type, String name) { | 196 | String _getKey(Type type, String name) { |
206 | return name == null ? type.toString() : type.toString() + name; | 197 | return name == null ? type.toString() : type.toString() + name; |
207 | } | 198 | } |
@@ -214,7 +205,7 @@ class GetInstance { | @@ -214,7 +205,7 @@ class GetInstance { | ||
214 | } | 205 | } |
215 | 206 | ||
216 | /// Delete class instance on [S] and clean memory | 207 | /// Delete class instance on [S] and clean memory |
217 | - Future<bool> delete<S>({String tag, String key}) async { | 208 | + Future<bool> delete<S>({String tag, String key, bool force = false}) async { |
218 | String newKey; | 209 | String newKey; |
219 | if (key == null) { | 210 | if (key == null) { |
220 | newKey = _getKey(S, tag); | 211 | newKey = _getKey(S, tag); |
@@ -228,13 +219,16 @@ class GetInstance { | @@ -228,13 +219,16 @@ class GetInstance { | ||
228 | } | 219 | } |
229 | 220 | ||
230 | FcBuilder builder = GetConfig._singl[newKey] as FcBuilder; | 221 | FcBuilder builder = GetConfig._singl[newKey] as FcBuilder; |
231 | - if (builder.permanent) { | 222 | + if (builder.permanent && !force) { |
232 | print( | 223 | print( |
233 | '[GETX] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.'); | 224 | '[GETX] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.'); |
234 | return false; | 225 | return false; |
235 | } | 226 | } |
236 | final i = builder.dependency; | 227 | final i = builder.dependency; |
237 | 228 | ||
229 | + if (i is GetxService && !force) { | ||
230 | + return false; | ||
231 | + } | ||
238 | if (i is DisposableInterface) { | 232 | if (i is DisposableInterface) { |
239 | await i.onClose(); | 233 | await i.onClose(); |
240 | if (GetConfig.isLogEnable) print('[GETX] onClose of $newKey called'); | 234 | if (GetConfig.isLogEnable) print('[GETX] onClose of $newKey called'); |
@@ -258,3 +252,27 @@ class GetInstance { | @@ -258,3 +252,27 @@ class GetInstance { | ||
258 | bool isPrepared<S>({String tag}) => | 252 | bool isPrepared<S>({String tag}) => |
259 | GetConfig._factory.containsKey(_getKey(S, tag)); | 253 | GetConfig._factory.containsKey(_getKey(S, tag)); |
260 | } | 254 | } |
255 | + | ||
256 | +typedef FcBuilderFunc<S> = S Function(); | ||
257 | + | ||
258 | +typedef FcBuilderFuncAsync<S> = Future<S> Function(); | ||
259 | + | ||
260 | +class FcBuilder<S> { | ||
261 | + bool isSingleton; | ||
262 | + FcBuilderFunc builderFunc; | ||
263 | + S dependency; | ||
264 | + bool permanent = false; | ||
265 | + | ||
266 | + FcBuilder(this.isSingleton, this.builderFunc, this.permanent); | ||
267 | + | ||
268 | + S getSependency() { | ||
269 | + if (isSingleton) { | ||
270 | + if (dependency == null) { | ||
271 | + dependency = builderFunc() as S; | ||
272 | + } | ||
273 | + return dependency; | ||
274 | + } else { | ||
275 | + return builderFunc() as S; | ||
276 | + } | ||
277 | + } | ||
278 | +} |
lib/src/instance/instance_manager.dart
0 → 100644
lib/src/navigation/extension_navigation.dart
0 → 100644
1 | +import 'package:flutter/material.dart'; | ||
2 | +import 'package:flutter/scheduler.dart'; | ||
3 | +import 'package:get/src/get_interface.dart'; | ||
4 | +import 'package:get/src/instance/instance_manager.dart'; | ||
5 | +import 'package:get/src/navigation/route_manager.dart'; | ||
6 | + | ||
7 | +import 'root/parse_route.dart'; | ||
8 | +import 'routes/bindings_interface.dart'; | ||
9 | + | ||
10 | +/// It replaces the Flutter Navigator, but needs no context. | ||
11 | +/// You can to use navigator.push(YourRoute()) rather Navigator.push(context, YourRoute()); | ||
12 | +NavigatorState get navigator => Get.key.currentState; | ||
13 | + | ||
14 | +extension GetNavigation on GetInterface { | ||
15 | + /// Pushes a new [page] to the stack | ||
16 | + /// | ||
17 | + /// It has the advantage of not needing context, | ||
18 | + /// so you can call from your business logic | ||
19 | + /// | ||
20 | + /// You can set a custom [transition], and a transition [duration]. | ||
21 | + /// | ||
22 | + /// You can send any type of value to the other route in the [arguments]. | ||
23 | + /// | ||
24 | + /// Just like native routing in Flutter, you can push a route | ||
25 | + /// as a [fullscreenDialog], | ||
26 | + /// | ||
27 | + /// [id] is for when you are using nested navigation, | ||
28 | + /// as explained in documentation | ||
29 | + /// | ||
30 | + /// If you want the same behavior of ios that pops a route when the user drag, | ||
31 | + /// you can set [popGesture] to true | ||
32 | + /// | ||
33 | + /// If you're using the [Bindings] api, you must define it here | ||
34 | + /// | ||
35 | + /// By default, GetX will prevent you from push a route that you already in, | ||
36 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
37 | + Future<T> to<T>( | ||
38 | + Widget page, { | ||
39 | + bool opaque, | ||
40 | + Transition transition, | ||
41 | + Duration duration, | ||
42 | + int id, | ||
43 | + bool fullscreenDialog = false, | ||
44 | + Object arguments, | ||
45 | + Bindings binding, | ||
46 | + preventDuplicates = true, | ||
47 | + bool popGesture, | ||
48 | + }) { | ||
49 | + if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { | ||
50 | + return null; | ||
51 | + } | ||
52 | + return global(id).currentState.push( | ||
53 | + GetPageRoute( | ||
54 | + opaque: opaque ?? true, | ||
55 | + page: () => page, | ||
56 | + settings: RouteSettings( | ||
57 | + name: '/${page.runtimeType}', | ||
58 | + arguments: arguments, | ||
59 | + ), | ||
60 | + popGesture: popGesture ?? defaultPopGesture, | ||
61 | + transition: transition ?? defaultTransition, | ||
62 | + fullscreenDialog: fullscreenDialog, | ||
63 | + binding: binding, | ||
64 | + transitionDuration: duration ?? defaultDurationTransition, | ||
65 | + ), | ||
66 | + ); | ||
67 | + } | ||
68 | + | ||
69 | + /// Pushes a new named [page] to the stack | ||
70 | + /// | ||
71 | + /// It has the advantage of not needing context, so you can call | ||
72 | + /// from your business logic. | ||
73 | + /// | ||
74 | + /// You can send any type of value to the other route in the [arguments]. | ||
75 | + /// | ||
76 | + /// [id] is for when you are using nested navigation, | ||
77 | + /// as explained in documentation | ||
78 | + /// | ||
79 | + /// By default, GetX will prevent you from push a route that you already in, | ||
80 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
81 | + /// | ||
82 | + /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
83 | + Future<T> toNamed<T>( | ||
84 | + String page, { | ||
85 | + Object arguments, | ||
86 | + int id, | ||
87 | + preventDuplicates = true, | ||
88 | + }) { | ||
89 | + if (preventDuplicates && page == currentRoute) { | ||
90 | + return null; | ||
91 | + } | ||
92 | + return global(id).currentState.pushNamed(page, arguments: arguments); | ||
93 | + } | ||
94 | + | ||
95 | + /// Pop the current named [page] in the stack and push a new one in its place | ||
96 | + /// | ||
97 | + /// It has the advantage of not needing context, so you can call | ||
98 | + /// from your business logic. | ||
99 | + /// | ||
100 | + /// You can send any type of value to the other route in the [arguments]. | ||
101 | + /// | ||
102 | + /// [id] is for when you are using nested navigation, | ||
103 | + /// as explained in documentation | ||
104 | + /// | ||
105 | + /// By default, GetX will prevent you from push a route that you already in, | ||
106 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
107 | + /// | ||
108 | + /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
109 | + Future<T> offNamed<T>( | ||
110 | + String page, { | ||
111 | + Object arguments, | ||
112 | + int id, | ||
113 | + preventDuplicates = true, | ||
114 | + }) { | ||
115 | + if (preventDuplicates && page == currentRoute) { | ||
116 | + return null; | ||
117 | + } | ||
118 | + return global(id) | ||
119 | + .currentState | ||
120 | + .pushReplacementNamed(page, arguments: arguments); | ||
121 | + } | ||
122 | + | ||
123 | + /// Calls pop several times in the stack until [predicate] returns true | ||
124 | + /// | ||
125 | + /// [id] is for when you are using nested navigation, | ||
126 | + /// as explained in documentation | ||
127 | + /// | ||
128 | + /// [predicate] can be used like this: | ||
129 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
130 | + /// | ||
131 | + /// or also like this: | ||
132 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
133 | + void until(RoutePredicate predicate, {int id}) { | ||
134 | + // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
135 | + // when widget don't mounted | ||
136 | + return global(id).currentState.popUntil(predicate); | ||
137 | + } | ||
138 | + | ||
139 | + /// Push the given [page], and then pop several [pages] in the stack until | ||
140 | + /// [predicate] returns true | ||
141 | + /// | ||
142 | + /// [id] is for when you are using nested navigation, | ||
143 | + /// as explained in documentation | ||
144 | + /// | ||
145 | + /// [predicate] can be used like this: | ||
146 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
147 | + /// | ||
148 | + /// or also like this: | ||
149 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
150 | + Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { | ||
151 | + // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
152 | + // when widget don't mounted | ||
153 | + return global(id).currentState.pushAndRemoveUntil(page, predicate); | ||
154 | + } | ||
155 | + | ||
156 | + /// Push the given named [page], and then pop several pages in the stack | ||
157 | + /// until [predicate] returns true | ||
158 | + /// | ||
159 | + /// You can send any type of value to the other route in the [arguments]. | ||
160 | + /// | ||
161 | + /// [id] is for when you are using nested navigation, | ||
162 | + /// as explained in documentation | ||
163 | + /// | ||
164 | + /// [predicate] can be used like this: | ||
165 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
166 | + /// or also like | ||
167 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
168 | + /// | ||
169 | + /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
170 | + Future<T> offNamedUntil<T>( | ||
171 | + String page, | ||
172 | + RoutePredicate predicate, { | ||
173 | + int id, | ||
174 | + Object arguments, | ||
175 | + }) { | ||
176 | + return global(id) | ||
177 | + .currentState | ||
178 | + .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); | ||
179 | + } | ||
180 | + | ||
181 | + /// Pop the current named page and pushes a new [page] to the stack in its place | ||
182 | + /// | ||
183 | + /// You can send any type of value to the other route in the [arguments]. | ||
184 | + /// It is very similar to `offNamed()` but use a different approach | ||
185 | + /// | ||
186 | + /// The `offNamed()` pop a page, and goes to the next. The `offAndToNamed()` goes | ||
187 | + /// to the next page, and removes the previous one. The route transition | ||
188 | + /// animation is different. | ||
189 | + Future<T> offAndToNamed<T>(String page, | ||
190 | + {Object arguments, int id, dynamic result}) { | ||
191 | + return global(id) | ||
192 | + .currentState | ||
193 | + .popAndPushNamed(page, arguments: arguments, result: result); | ||
194 | + } | ||
195 | + | ||
196 | + /// Remove a specific [route] from the stack | ||
197 | + /// | ||
198 | + /// [id] is for when you are using nested navigation, | ||
199 | + /// as explained in documentation | ||
200 | + void removeRoute(Route<dynamic> route, {int id}) { | ||
201 | + return global(id).currentState.removeRoute(route); | ||
202 | + } | ||
203 | + | ||
204 | + /// Push a named [page] and remove all other pages from stack | ||
205 | + /// | ||
206 | + /// It has the advantage of not needing context, so you can | ||
207 | + /// call from your business logic. | ||
208 | + /// | ||
209 | + /// You can send any type of value to the other route in the [arguments]. | ||
210 | + /// | ||
211 | + /// [id] is for when you are using nested navigation, | ||
212 | + /// as explained in documentation | ||
213 | + /// | ||
214 | + /// Note: Always put a slash on the route ('/page1'), to avoid unexpected errors | ||
215 | + Future<T> offAllNamed<T>(String newRouteName, | ||
216 | + {RoutePredicate predicate, Object arguments, int id}) { | ||
217 | + var route = (Route<dynamic> rota) => false; | ||
218 | + | ||
219 | + return global(id).currentState.pushNamedAndRemoveUntil( | ||
220 | + newRouteName, predicate ?? route, | ||
221 | + arguments: arguments); | ||
222 | + } | ||
223 | + | ||
224 | + /// Returns true if a snackbar, dialog or bottomsheet is currently showing in the screen | ||
225 | + bool get isOverlaysOpen => | ||
226 | + (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); | ||
227 | + | ||
228 | + /// returns true if there is no snackbar, dialog or bottomsheet open | ||
229 | + bool get isOverlaysClosed => | ||
230 | + (!isSnackbarOpen && !isDialogOpen && !isBottomSheetOpen); | ||
231 | + | ||
232 | + /// Pop the current page, snackbar, dialog or bottomsheet in the stack | ||
233 | + /// | ||
234 | + /// if your set [closeOverlays] to true, Get.back() will close the currently open | ||
235 | + /// snackbar/dialog/bottomsheet AND the current page | ||
236 | + /// | ||
237 | + /// [id] is for when you are using nested navigation, | ||
238 | + /// as explained in documentation | ||
239 | + /// | ||
240 | + /// It has the advantage of not needing context, so you can call | ||
241 | + /// from your business logic. | ||
242 | + void back({ | ||
243 | + dynamic result, | ||
244 | + bool closeOverlays = false, | ||
245 | + bool canPop = true, | ||
246 | + int id, | ||
247 | + }) { | ||
248 | + if (closeOverlays && isOverlaysOpen) { | ||
249 | + navigator.popUntil((route) { | ||
250 | + return (isOverlaysClosed); | ||
251 | + }); | ||
252 | + } | ||
253 | + if (canPop) { | ||
254 | + if (global(id).currentState.canPop()) { | ||
255 | + global(id).currentState.pop(result); | ||
256 | + } | ||
257 | + } else { | ||
258 | + global(id).currentState.pop(result); | ||
259 | + } | ||
260 | + } | ||
261 | + | ||
262 | + /// Close as many routes as defined by [times] | ||
263 | + void close(int times, [int id]) { | ||
264 | + if ((times == null) || (times < 1)) { | ||
265 | + times = 1; | ||
266 | + } | ||
267 | + int count = 0; | ||
268 | + void back = global(id).currentState.popUntil((route) { | ||
269 | + return count++ == times; | ||
270 | + }); | ||
271 | + return back; | ||
272 | + } | ||
273 | + | ||
274 | + /// Pop the current page and pushes a new [page] to the stack | ||
275 | + /// | ||
276 | + /// It has the advantage of not needing context, | ||
277 | + /// so you can call from your business logic | ||
278 | + /// | ||
279 | + /// You can set a custom [transition], and a transition [duration]. | ||
280 | + /// | ||
281 | + /// You can send any type of value to the other route in the [arguments]. | ||
282 | + /// | ||
283 | + /// Just like native routing in Flutter, you can push a route | ||
284 | + /// as a [fullscreenDialog], | ||
285 | + /// | ||
286 | + /// [id] is for when you are using nested navigation, | ||
287 | + /// as explained in documentation | ||
288 | + /// | ||
289 | + /// If you want the same behavior of ios that pops a route when the user drag, | ||
290 | + /// you can set [popGesture] to true | ||
291 | + /// | ||
292 | + /// If you're using the [Bindings] api, you must define it here | ||
293 | + /// | ||
294 | + /// By default, GetX will prevent you from push a route that you already in, | ||
295 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
296 | + Future<T> off<T>( | ||
297 | + Widget page, { | ||
298 | + bool opaque = false, | ||
299 | + Transition transition, | ||
300 | + bool popGesture, | ||
301 | + int id, | ||
302 | + Object arguments, | ||
303 | + Bindings binding, | ||
304 | + bool fullscreenDialog = false, | ||
305 | + preventDuplicates = true, | ||
306 | + Duration duration, | ||
307 | + }) { | ||
308 | + if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { | ||
309 | + return null; | ||
310 | + } | ||
311 | + return global(id).currentState.pushReplacement(GetPageRoute( | ||
312 | + opaque: opaque ?? true, | ||
313 | + page: () => page, | ||
314 | + binding: binding, | ||
315 | + settings: | ||
316 | + RouteSettings(name: '/${page.runtimeType}', arguments: arguments), | ||
317 | + fullscreenDialog: fullscreenDialog, | ||
318 | + popGesture: popGesture ?? defaultPopGesture, | ||
319 | + transition: transition ?? defaultTransition, | ||
320 | + transitionDuration: duration ?? defaultDurationTransition)); | ||
321 | + } | ||
322 | + | ||
323 | + /// Pop all pages in the stack and pushes a new [page] to it | ||
324 | + /// | ||
325 | + /// It has the advantage of not needing context, | ||
326 | + /// so you can call from your business logic | ||
327 | + /// | ||
328 | + /// You can set a custom [transition], and a transition [duration]. | ||
329 | + /// | ||
330 | + /// You can send any type of value to the other route in the [arguments]. | ||
331 | + /// | ||
332 | + /// Just like native routing in Flutter, you can push a route | ||
333 | + /// as a [fullscreenDialog], | ||
334 | + /// | ||
335 | + /// [predicate] can be used like this: | ||
336 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
337 | + /// or also like | ||
338 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
339 | + /// | ||
340 | + /// [id] is for when you are using nested navigation, | ||
341 | + /// as explained in documentation | ||
342 | + /// | ||
343 | + /// If you want the same behavior of ios that pops a route when the user drag, | ||
344 | + /// you can set [popGesture] to true | ||
345 | + /// | ||
346 | + /// If you're using the [Bindings] api, you must define it here | ||
347 | + /// | ||
348 | + /// By default, GetX will prevent you from push a route that you already in, | ||
349 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
350 | + Future<T> offAll<T>( | ||
351 | + Widget page, { | ||
352 | + RoutePredicate predicate, | ||
353 | + bool opaque = false, | ||
354 | + bool popGesture, | ||
355 | + int id, | ||
356 | + Object arguments, | ||
357 | + Bindings binding, | ||
358 | + bool fullscreenDialog = false, | ||
359 | + Duration duration, | ||
360 | + Transition transition, | ||
361 | + }) { | ||
362 | + var route = (Route<dynamic> rota) => false; | ||
363 | + | ||
364 | + return global(id).currentState.pushAndRemoveUntil( | ||
365 | + GetPageRoute( | ||
366 | + opaque: opaque ?? true, | ||
367 | + popGesture: popGesture ?? defaultPopGesture, | ||
368 | + page: () => page, | ||
369 | + binding: binding, | ||
370 | + settings: | ||
371 | + RouteSettings(name: '/${page.runtimeType}', arguments: arguments), | ||
372 | + fullscreenDialog: fullscreenDialog, | ||
373 | + transition: transition ?? defaultTransition, | ||
374 | + transitionDuration: duration ?? defaultDurationTransition, | ||
375 | + ), | ||
376 | + predicate ?? route); | ||
377 | + } | ||
378 | + | ||
379 | + /// Show a dialog | ||
380 | + Future<T> dialog<T>( | ||
381 | + Widget child, { | ||
382 | + bool barrierDismissible = true, | ||
383 | + bool useRootNavigator = true, | ||
384 | + // RouteSettings routeSettings | ||
385 | + }) { | ||
386 | + return showDialog( | ||
387 | + barrierDismissible: barrierDismissible, | ||
388 | + useRootNavigator: useRootNavigator, | ||
389 | + routeSettings: RouteSettings(name: 'dialog'), | ||
390 | + context: overlayContext, | ||
391 | + builder: (_) { | ||
392 | + return child; | ||
393 | + }, | ||
394 | + ); | ||
395 | + } | ||
396 | + | ||
397 | + /// Api from showGeneralDialog with no context | ||
398 | + Future<T> generalDialog<T>({ | ||
399 | + @required RoutePageBuilder pageBuilder, | ||
400 | + String barrierLabel = "Dismiss", | ||
401 | + bool barrierDismissible = true, | ||
402 | + Color barrierColor = const Color(0x80000000), | ||
403 | + Duration transitionDuration = const Duration(milliseconds: 200), | ||
404 | + RouteTransitionsBuilder transitionBuilder, | ||
405 | + bool useRootNavigator = true, | ||
406 | + RouteSettings routeSettings, | ||
407 | + }) { | ||
408 | + return showGeneralDialog( | ||
409 | + pageBuilder: pageBuilder, | ||
410 | + barrierDismissible: barrierDismissible, | ||
411 | + barrierLabel: barrierLabel, | ||
412 | + barrierColor: barrierColor, | ||
413 | + transitionDuration: transitionDuration, | ||
414 | + transitionBuilder: transitionBuilder, | ||
415 | + useRootNavigator: useRootNavigator, | ||
416 | + routeSettings: RouteSettings(name: 'dialog'), | ||
417 | + context: overlayContext, | ||
418 | + ); | ||
419 | + } | ||
420 | + | ||
421 | + Future<T> defaultDialog<T>({ | ||
422 | + String title = "Alert", | ||
423 | + Widget content, | ||
424 | + VoidCallback onConfirm, | ||
425 | + VoidCallback onCancel, | ||
426 | + VoidCallback onCustom, | ||
427 | + Color cancelTextColor, | ||
428 | + Color confirmTextColor, | ||
429 | + String textConfirm, | ||
430 | + String textCancel, | ||
431 | + String textCustom, | ||
432 | + Widget confirm, | ||
433 | + Widget cancel, | ||
434 | + Widget custom, | ||
435 | + Color backgroundColor, | ||
436 | + Color buttonColor, | ||
437 | + String middleText = "Dialog made in 3 lines of code", | ||
438 | + double radius = 20.0, | ||
439 | + List<Widget> actions, | ||
440 | + }) { | ||
441 | + bool leanCancel = onCancel != null || textCancel != null; | ||
442 | + bool leanConfirm = onConfirm != null || textConfirm != null; | ||
443 | + actions ??= []; | ||
444 | + | ||
445 | + if (cancel != null) { | ||
446 | + actions.add(cancel); | ||
447 | + } else { | ||
448 | + if (leanCancel) { | ||
449 | + actions.add(FlatButton( | ||
450 | + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | ||
451 | + onPressed: () { | ||
452 | + onCancel?.call(); | ||
453 | + back(); | ||
454 | + }, | ||
455 | + padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8), | ||
456 | + child: Text( | ||
457 | + textCancel ?? "Cancel", | ||
458 | + style: TextStyle(color: cancelTextColor ?? theme.accentColor), | ||
459 | + ), | ||
460 | + shape: RoundedRectangleBorder( | ||
461 | + side: BorderSide( | ||
462 | + color: buttonColor ?? theme.accentColor, | ||
463 | + width: 2, | ||
464 | + style: BorderStyle.solid), | ||
465 | + borderRadius: BorderRadius.circular(100)), | ||
466 | + )); | ||
467 | + } | ||
468 | + } | ||
469 | + if (confirm != null) { | ||
470 | + actions.add(confirm); | ||
471 | + } else { | ||
472 | + if (leanConfirm) { | ||
473 | + actions.add(FlatButton( | ||
474 | + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | ||
475 | + color: buttonColor ?? theme.accentColor, | ||
476 | + shape: RoundedRectangleBorder( | ||
477 | + borderRadius: BorderRadius.circular(100)), | ||
478 | + child: Text( | ||
479 | + textConfirm ?? "Ok", | ||
480 | + style: TextStyle(color: confirmTextColor ?? theme.primaryColor), | ||
481 | + ), | ||
482 | + onPressed: () { | ||
483 | + onConfirm?.call(); | ||
484 | + })); | ||
485 | + } | ||
486 | + } | ||
487 | + return dialog(AlertDialog( | ||
488 | + titlePadding: EdgeInsets.all(8), | ||
489 | + contentPadding: EdgeInsets.all(8), | ||
490 | + backgroundColor: backgroundColor ?? theme.dialogBackgroundColor, | ||
491 | + shape: RoundedRectangleBorder( | ||
492 | + borderRadius: BorderRadius.all(Radius.circular(radius))), | ||
493 | + title: Text(title, textAlign: TextAlign.center), | ||
494 | + content: Column( | ||
495 | + crossAxisAlignment: CrossAxisAlignment.center, | ||
496 | + mainAxisSize: MainAxisSize.min, | ||
497 | + children: [ | ||
498 | + content ?? Text(middleText ?? "", textAlign: TextAlign.center), | ||
499 | + SizedBox(height: 16), | ||
500 | + ButtonTheme( | ||
501 | + minWidth: 78.0, | ||
502 | + height: 34.0, | ||
503 | + child: Wrap( | ||
504 | + alignment: WrapAlignment.center, | ||
505 | + spacing: 8, | ||
506 | + runSpacing: 8, | ||
507 | + children: actions, | ||
508 | + ), | ||
509 | + ) | ||
510 | + ], | ||
511 | + ), | ||
512 | + // actions: actions, // ?? <Widget>[cancelButton, confirmButton], | ||
513 | + buttonPadding: EdgeInsets.zero, | ||
514 | + )); | ||
515 | + } | ||
516 | + | ||
517 | + Future<T> bottomSheet<T>( | ||
518 | + Widget bottomsheet, { | ||
519 | + Color backgroundColor, | ||
520 | + double elevation, | ||
521 | + ShapeBorder shape, | ||
522 | + Clip clipBehavior, | ||
523 | + Color barrierColor, | ||
524 | + bool ignoreSafeArea, | ||
525 | + bool isScrollControlled = false, | ||
526 | + bool useRootNavigator = false, | ||
527 | + bool isDismissible = true, | ||
528 | + bool enableDrag = true, | ||
529 | + }) { | ||
530 | + assert(bottomsheet != null); | ||
531 | + assert(isScrollControlled != null); | ||
532 | + assert(useRootNavigator != null); | ||
533 | + assert(isDismissible != null); | ||
534 | + assert(enableDrag != null); | ||
535 | + | ||
536 | + return Navigator.of(overlayContext, rootNavigator: useRootNavigator) | ||
537 | + .push(GetModalBottomSheetRoute<T>( | ||
538 | + builder: (_) => bottomsheet, | ||
539 | + theme: Theme.of(key.currentContext, shadowThemeOnly: true), | ||
540 | + isScrollControlled: isScrollControlled, | ||
541 | + barrierLabel: | ||
542 | + MaterialLocalizations.of(key.currentContext).modalBarrierDismissLabel, | ||
543 | + backgroundColor: backgroundColor ?? Colors.transparent, | ||
544 | + elevation: elevation, | ||
545 | + shape: shape, | ||
546 | + removeTop: ignoreSafeArea ?? true, | ||
547 | + clipBehavior: clipBehavior, | ||
548 | + isDismissible: isDismissible, | ||
549 | + modalBarrierColor: barrierColor, | ||
550 | + settings: RouteSettings(name: "bottomsheet"), | ||
551 | + enableDrag: enableDrag, | ||
552 | + )); | ||
553 | + } | ||
554 | + | ||
555 | + void rawSnackbar( | ||
556 | + {String title, | ||
557 | + String message, | ||
558 | + Widget titleText, | ||
559 | + Widget messageText, | ||
560 | + Widget icon, | ||
561 | + bool instantInit = true, | ||
562 | + bool shouldIconPulse = true, | ||
563 | + double maxWidth, | ||
564 | + EdgeInsets margin = const EdgeInsets.all(0.0), | ||
565 | + EdgeInsets padding = const EdgeInsets.all(16), | ||
566 | + double borderRadius = 0.0, | ||
567 | + Color borderColor, | ||
568 | + double borderWidth = 1.0, | ||
569 | + Color backgroundColor = const Color(0xFF303030), | ||
570 | + Color leftBarIndicatorColor, | ||
571 | + List<BoxShadow> boxShadows, | ||
572 | + Gradient backgroundGradient, | ||
573 | + FlatButton mainButton, | ||
574 | + OnTap onTap, | ||
575 | + Duration duration = const Duration(seconds: 3), | ||
576 | + bool isDismissible = true, | ||
577 | + SnackDismissDirection dismissDirection = SnackDismissDirection.VERTICAL, | ||
578 | + bool showProgressIndicator = false, | ||
579 | + AnimationController progressIndicatorController, | ||
580 | + Color progressIndicatorBackgroundColor, | ||
581 | + Animation<Color> progressIndicatorValueColor, | ||
582 | + SnackPosition snackPosition = SnackPosition.BOTTOM, | ||
583 | + SnackStyle snackStyle = SnackStyle.FLOATING, | ||
584 | + Curve forwardAnimationCurve = Curves.easeOutCirc, | ||
585 | + Curve reverseAnimationCurve = Curves.easeOutCirc, | ||
586 | + Duration animationDuration = const Duration(seconds: 1), | ||
587 | + SnackStatusCallback onStatusChanged, | ||
588 | + double barBlur = 0.0, | ||
589 | + double overlayBlur = 0.0, | ||
590 | + Color overlayColor = Colors.transparent, | ||
591 | + Form userInputForm}) { | ||
592 | + GetBar getBar = GetBar( | ||
593 | + title: title, | ||
594 | + message: message, | ||
595 | + titleText: titleText, | ||
596 | + messageText: messageText, | ||
597 | + snackPosition: snackPosition, | ||
598 | + borderRadius: borderRadius, | ||
599 | + margin: margin, | ||
600 | + duration: duration, | ||
601 | + barBlur: barBlur, | ||
602 | + backgroundColor: backgroundColor, | ||
603 | + icon: icon, | ||
604 | + shouldIconPulse: shouldIconPulse, | ||
605 | + maxWidth: maxWidth, | ||
606 | + padding: padding, | ||
607 | + borderColor: borderColor, | ||
608 | + borderWidth: borderWidth, | ||
609 | + leftBarIndicatorColor: leftBarIndicatorColor, | ||
610 | + boxShadows: boxShadows, | ||
611 | + backgroundGradient: backgroundGradient, | ||
612 | + mainButton: mainButton, | ||
613 | + onTap: onTap, | ||
614 | + isDismissible: isDismissible, | ||
615 | + dismissDirection: dismissDirection, | ||
616 | + showProgressIndicator: showProgressIndicator ?? false, | ||
617 | + progressIndicatorController: progressIndicatorController, | ||
618 | + progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, | ||
619 | + progressIndicatorValueColor: progressIndicatorValueColor, | ||
620 | + snackStyle: snackStyle, | ||
621 | + forwardAnimationCurve: forwardAnimationCurve, | ||
622 | + reverseAnimationCurve: reverseAnimationCurve, | ||
623 | + animationDuration: animationDuration, | ||
624 | + overlayBlur: overlayBlur, | ||
625 | + overlayColor: overlayColor, | ||
626 | + userInputForm: userInputForm); | ||
627 | + | ||
628 | + if (instantInit) { | ||
629 | + getBar.show(); | ||
630 | + } else { | ||
631 | + SchedulerBinding.instance.addPostFrameCallback((_) { | ||
632 | + getBar.show(); | ||
633 | + }); | ||
634 | + } | ||
635 | + } | ||
636 | + | ||
637 | + void snackbar(String title, String message, | ||
638 | + {Color colorText, | ||
639 | + Duration duration, | ||
640 | + | ||
641 | + /// with instantInit = false you can put snackbar on initState | ||
642 | + bool instantInit = true, | ||
643 | + SnackPosition snackPosition, | ||
644 | + Widget titleText, | ||
645 | + Widget messageText, | ||
646 | + Widget icon, | ||
647 | + bool shouldIconPulse, | ||
648 | + double maxWidth, | ||
649 | + EdgeInsets margin, | ||
650 | + EdgeInsets padding, | ||
651 | + double borderRadius, | ||
652 | + Color borderColor, | ||
653 | + double borderWidth, | ||
654 | + Color backgroundColor, | ||
655 | + Color leftBarIndicatorColor, | ||
656 | + List<BoxShadow> boxShadows, | ||
657 | + Gradient backgroundGradient, | ||
658 | + FlatButton mainButton, | ||
659 | + OnTap onTap, | ||
660 | + bool isDismissible, | ||
661 | + bool showProgressIndicator, | ||
662 | + SnackDismissDirection dismissDirection, | ||
663 | + AnimationController progressIndicatorController, | ||
664 | + Color progressIndicatorBackgroundColor, | ||
665 | + Animation<Color> progressIndicatorValueColor, | ||
666 | + SnackStyle snackStyle, | ||
667 | + Curve forwardAnimationCurve, | ||
668 | + Curve reverseAnimationCurve, | ||
669 | + Duration animationDuration, | ||
670 | + double barBlur, | ||
671 | + double overlayBlur, | ||
672 | + Color overlayColor, | ||
673 | + Form userInputForm}) { | ||
674 | + GetBar getBar = GetBar( | ||
675 | + titleText: (title == null) | ||
676 | + ? null | ||
677 | + : titleText ?? | ||
678 | + Text( | ||
679 | + title, | ||
680 | + style: TextStyle( | ||
681 | + color: colorText ?? theme.iconTheme.color, | ||
682 | + fontWeight: FontWeight.w800, | ||
683 | + fontSize: 16), | ||
684 | + ), | ||
685 | + messageText: messageText ?? | ||
686 | + Text( | ||
687 | + message, | ||
688 | + style: TextStyle( | ||
689 | + color: colorText ?? theme.iconTheme.color, | ||
690 | + fontWeight: FontWeight.w300, | ||
691 | + fontSize: 14), | ||
692 | + ), | ||
693 | + snackPosition: snackPosition ?? SnackPosition.TOP, | ||
694 | + borderRadius: borderRadius ?? 15, | ||
695 | + margin: margin ?? EdgeInsets.symmetric(horizontal: 10), | ||
696 | + duration: duration ?? Duration(seconds: 3), | ||
697 | + barBlur: barBlur ?? 7.0, | ||
698 | + backgroundColor: backgroundColor ?? Colors.grey.withOpacity(0.2), | ||
699 | + icon: icon, | ||
700 | + shouldIconPulse: shouldIconPulse ?? true, | ||
701 | + maxWidth: maxWidth, | ||
702 | + padding: padding ?? EdgeInsets.all(16), | ||
703 | + borderColor: borderColor, | ||
704 | + borderWidth: borderWidth, | ||
705 | + leftBarIndicatorColor: leftBarIndicatorColor, | ||
706 | + boxShadows: boxShadows, | ||
707 | + backgroundGradient: backgroundGradient, | ||
708 | + mainButton: mainButton, | ||
709 | + onTap: onTap, | ||
710 | + isDismissible: isDismissible ?? true, | ||
711 | + dismissDirection: dismissDirection ?? SnackDismissDirection.VERTICAL, | ||
712 | + showProgressIndicator: showProgressIndicator ?? false, | ||
713 | + progressIndicatorController: progressIndicatorController, | ||
714 | + progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, | ||
715 | + progressIndicatorValueColor: progressIndicatorValueColor, | ||
716 | + snackStyle: snackStyle ?? SnackStyle.FLOATING, | ||
717 | + forwardAnimationCurve: forwardAnimationCurve ?? Curves.easeOutCirc, | ||
718 | + reverseAnimationCurve: reverseAnimationCurve ?? Curves.easeOutCirc, | ||
719 | + animationDuration: animationDuration ?? Duration(seconds: 1), | ||
720 | + overlayBlur: overlayBlur ?? 0.0, | ||
721 | + overlayColor: overlayColor ?? Colors.transparent, | ||
722 | + userInputForm: userInputForm); | ||
723 | + | ||
724 | + if (instantInit) { | ||
725 | + getBar.show(); | ||
726 | + } else { | ||
727 | + routing.isSnackbar = true; | ||
728 | + SchedulerBinding.instance.addPostFrameCallback((_) { | ||
729 | + getBar.show(); | ||
730 | + }); | ||
731 | + } | ||
732 | + } | ||
733 | + | ||
734 | + void addPages(List<GetPage> getPages) { | ||
735 | + if (getPages != null) { | ||
736 | + if (routeTree == null) routeTree = ParseRouteTree(); | ||
737 | + getPages.forEach((element) { | ||
738 | + routeTree.addRoute(element); | ||
739 | + }); | ||
740 | + } | ||
741 | + } | ||
742 | + | ||
743 | + void addPage(GetPage getPage) { | ||
744 | + if (getPage != null) { | ||
745 | + if (routeTree == null) routeTree = ParseRouteTree(); | ||
746 | + routeTree.addRoute(getPage); | ||
747 | + } | ||
748 | + } | ||
749 | + | ||
750 | + /// change default config of Get | ||
751 | + void config( | ||
752 | + {bool enableLog, | ||
753 | + bool defaultPopGesture, | ||
754 | + bool defaultOpaqueRoute, | ||
755 | + Duration defaultDurationTransition, | ||
756 | + bool defaultGlobalState, | ||
757 | + Transition defaultTransition}) { | ||
758 | + if (enableLog != null) { | ||
759 | + GetConfig.isLogEnable = enableLog; | ||
760 | + } | ||
761 | + if (defaultPopGesture != null) { | ||
762 | + this.defaultPopGesture = defaultPopGesture; | ||
763 | + } | ||
764 | + if (defaultOpaqueRoute != null) { | ||
765 | + this.defaultOpaqueRoute = defaultOpaqueRoute; | ||
766 | + } | ||
767 | + if (defaultTransition != null) { | ||
768 | + this.defaultTransition = defaultTransition; | ||
769 | + } | ||
770 | + | ||
771 | + if (defaultDurationTransition != null) { | ||
772 | + this.defaultDurationTransition = defaultDurationTransition; | ||
773 | + } | ||
774 | + | ||
775 | + if (defaultGlobalState != null) { | ||
776 | + this.defaultGlobalState = defaultGlobalState; | ||
777 | + } | ||
778 | + } | ||
779 | + | ||
780 | + void updateLocale(Locale l) { | ||
781 | + locale = l; | ||
782 | + forceAppUpdate(); | ||
783 | + } | ||
784 | + | ||
785 | + void forceAppUpdate() { | ||
786 | + void rebuild(Element el) { | ||
787 | + el.markNeedsBuild(); | ||
788 | + el.visitChildren(rebuild); | ||
789 | + } | ||
790 | + | ||
791 | + (context as Element).visitChildren(rebuild); | ||
792 | + } | ||
793 | + | ||
794 | + void addTranslations(Map<String, Map<String, String>> tr) { | ||
795 | + translations.addAll(tr); | ||
796 | + } | ||
797 | + | ||
798 | + void appendTranslations(Map<String, Map<String, String>> tr) { | ||
799 | + tr.forEach((key, map) { | ||
800 | + if (Get.translations.containsKey(key)) { | ||
801 | + Get.translations[key].addAll(map); | ||
802 | + } else { | ||
803 | + Get.translations[key] = map; | ||
804 | + } | ||
805 | + }); | ||
806 | + } | ||
807 | + | ||
808 | + void changeTheme(ThemeData theme) { | ||
809 | + getxController.setTheme(theme); | ||
810 | + } | ||
811 | + | ||
812 | + void changeThemeMode(ThemeMode themeMode) { | ||
813 | + getxController.setThemeMode(themeMode); | ||
814 | + } | ||
815 | + | ||
816 | + GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { | ||
817 | + key = newKey; | ||
818 | + return key; | ||
819 | + } | ||
820 | + | ||
821 | + GlobalKey<NavigatorState> nestedKey(int key) { | ||
822 | + keys.putIfAbsent(key, () => GlobalKey<NavigatorState>()); | ||
823 | + return keys[key]; | ||
824 | + } | ||
825 | + | ||
826 | + GlobalKey<NavigatorState> global(int k) { | ||
827 | + if (k == null) { | ||
828 | + return key; | ||
829 | + } | ||
830 | + if (!keys.containsKey(k)) { | ||
831 | + throw 'route id not found'; | ||
832 | + } | ||
833 | + return keys[k]; | ||
834 | + } | ||
835 | + | ||
836 | + RouteSettings get routeSettings => settings; | ||
837 | + | ||
838 | + void setSettings(RouteSettings settings) { | ||
839 | + settings = settings; | ||
840 | + } | ||
841 | + | ||
842 | + /// give current arguments | ||
843 | + Object get arguments => routing.args; | ||
844 | + | ||
845 | + /// give name from current route | ||
846 | + String get currentRoute => routing.current; | ||
847 | + | ||
848 | + /// give name from previous route | ||
849 | + String get previousRoute => routing.previous; | ||
850 | + | ||
851 | + /// check if snackbar is open | ||
852 | + bool get isSnackbarOpen => routing.isSnackbar; | ||
853 | + | ||
854 | + /// check if dialog is open | ||
855 | + bool get isDialogOpen => routing.isDialog; | ||
856 | + | ||
857 | + /// check if bottomsheet is open | ||
858 | + bool get isBottomSheetOpen => routing.isBottomSheet; | ||
859 | + | ||
860 | + /// check a raw current route | ||
861 | + Route<dynamic> get rawRoute => routing.route; | ||
862 | + | ||
863 | + /// check if popGesture is enable | ||
864 | + bool get isPopGestureEnable => defaultPopGesture; | ||
865 | + | ||
866 | + /// check if default opaque route is enable | ||
867 | + bool get isOpaqueRouteDefault => defaultOpaqueRoute; | ||
868 | + | ||
869 | + /// give access to currentContext | ||
870 | + BuildContext get context => key.currentContext; | ||
871 | + | ||
872 | + /// give access to current Overlay Context | ||
873 | + BuildContext get overlayContext => key.currentState.overlay.context; | ||
874 | + | ||
875 | + /// give access to Theme.of(context) | ||
876 | + ThemeData get theme => Theme.of(context); | ||
877 | + | ||
878 | + /// give access to TextTheme.of(context) | ||
879 | + TextTheme get textTheme => Theme.of(context).textTheme; | ||
880 | + | ||
881 | + /// give access to Mediaquery.of(context) | ||
882 | + MediaQueryData get mediaQuery => MediaQuery.of(context); | ||
883 | + | ||
884 | + /// Check if dark mode theme is enable | ||
885 | + bool get isDarkMode => (theme.brightness == Brightness.dark); | ||
886 | + | ||
887 | + /// Check if dark mode theme is enable on platform on android Q+ | ||
888 | + bool get isPlatformDarkMode => | ||
889 | + (mediaQuery.platformBrightness == Brightness.dark); | ||
890 | + | ||
891 | + /// give access to Theme.of(context).iconTheme.color | ||
892 | + Color get iconColor => Theme.of(context).iconTheme.color; | ||
893 | + | ||
894 | + /// give access to FocusScope.of(context) | ||
895 | + FocusNode get focusScope => FocusManager.instance.primaryFocus; | ||
896 | + | ||
897 | + /// give access to Immutable MediaQuery.of(context).size.height | ||
898 | + double get height => MediaQuery.of(context).size.height; | ||
899 | + | ||
900 | + /// give access to Immutable MediaQuery.of(context).size.width | ||
901 | + double get width => MediaQuery.of(context).size.width; | ||
902 | +} |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | -import 'package:get/src/routes/get_route.dart'; | 2 | +import 'package:get/src/navigation/routes/get_route.dart'; |
3 | 3 | ||
4 | class GetPageMatch { | 4 | class GetPageMatch { |
5 | GetPageMatch(this.route); | 5 | GetPageMatch(this.route); |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | -import 'package:get/src/state/get_state.dart'; | 2 | +import 'package:get/src/state_manager/simple/get_state.dart'; |
3 | 3 | ||
4 | class GetMaterialController extends GetxController { | 4 | class GetMaterialController extends GetxController { |
5 | Key key; | 5 | Key key; |
@@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart'; | @@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart'; | ||
2 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
3 | import 'package:get/get.dart'; | 3 | import 'package:get/get.dart'; |
4 | import 'package:get/src/instance/get_instance.dart'; | 4 | import 'package:get/src/instance/get_instance.dart'; |
5 | -import 'package:get/src/routes/get_route.dart'; | 5 | +import 'package:get/src/navigation/routes/get_route.dart'; |
6 | import 'root_controller.dart'; | 6 | import 'root_controller.dart'; |
7 | import 'smart_management.dart'; | 7 | import 'smart_management.dart'; |
8 | 8 |
lib/src/navigation/route_manager.dart
0 → 100644
1 | +export 'routes/custom_transition.dart'; | ||
2 | +export 'routes/transitions_type.dart'; | ||
3 | +export 'routes/get_route.dart'; | ||
4 | +export 'routes/default_route.dart'; | ||
5 | +export 'routes/observers/route_observer.dart'; | ||
6 | +export 'root/root_widget.dart'; | ||
7 | +export 'snackbar/snack_route.dart'; | ||
8 | +export 'bottomsheet/bottomsheet.dart'; | ||
9 | +export 'snackbar/snack.dart'; | ||
10 | +export '../get_main.dart'; | ||
11 | +export 'routes/default_route.dart'; | ||
12 | +export 'root/smart_management.dart'; | ||
13 | +export 'extension_navigation.dart'; |
@@ -3,10 +3,10 @@ import 'dart:ui' show lerpDouble; | @@ -3,10 +3,10 @@ import 'dart:ui' show lerpDouble; | ||
3 | import 'package:flutter/cupertino.dart'; | 3 | import 'package:flutter/cupertino.dart'; |
4 | import 'package:flutter/gestures.dart'; | 4 | import 'package:flutter/gestures.dart'; |
5 | import 'package:flutter/material.dart'; | 5 | import 'package:flutter/material.dart'; |
6 | -import 'package:get/route_manager.dart'; | 6 | +import 'package:get/src/navigation/route_manager.dart'; |
7 | import 'package:get/src/get_main.dart'; | 7 | import 'package:get/src/get_main.dart'; |
8 | import 'package:get/src/instance/get_instance.dart'; | 8 | import 'package:get/src/instance/get_instance.dart'; |
9 | -import 'package:get/utils.dart'; | 9 | +import 'package:get/src/utils/utils.dart'; |
10 | import 'bindings_interface.dart'; | 10 | import 'bindings_interface.dart'; |
11 | import 'custom_transition.dart'; | 11 | import 'custom_transition.dart'; |
12 | import 'default_transitions.dart'; | 12 | import 'default_transitions.dart'; |
@@ -130,14 +130,6 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -130,14 +130,6 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
130 | bool get popGestureInProgress => isPopGestureInProgress(this); | 130 | bool get popGestureInProgress => isPopGestureInProgress(this); |
131 | 131 | ||
132 | @override | 132 | @override |
133 | - void dispose() { | ||
134 | - if (GetConfig.smartManagement != SmartManagement.onlyBuilder) { | ||
135 | - GetInstance().removeDependencyByRoute("${settings.name}"); | ||
136 | - } | ||
137 | - super.dispose(); | ||
138 | - } | ||
139 | - | ||
140 | - @override | ||
141 | Widget buildTransitions(BuildContext context, Animation<double> animation, | 133 | Widget buildTransitions(BuildContext context, Animation<double> animation, |
142 | Animation<double> secondaryAnimation, Widget child) { | 134 | Animation<double> secondaryAnimation, Widget child) { |
143 | if (fullscreenDialog && transition == null) { | 135 | if (fullscreenDialog && transition == null) { |
@@ -393,6 +385,15 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -393,6 +385,15 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
393 | : child); | 385 | : child); |
394 | } | 386 | } |
395 | } | 387 | } |
388 | + | ||
389 | + @override | ||
390 | + void dispose() { | ||
391 | + if (GetConfig.smartManagement != SmartManagement.onlyBuilder) { | ||
392 | + Future.delayed(Duration.zero, | ||
393 | + () => GetInstance().removeDependencyByRoute("${settings.name}")); | ||
394 | + } | ||
395 | + super.dispose(); | ||
396 | + } | ||
396 | } | 397 | } |
397 | 398 | ||
398 | const double _kBackGestureWidth = 20.0; | 399 | const double _kBackGestureWidth = 20.0; |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | -import 'package:get/src/routes/bindings_interface.dart'; | 2 | +import 'package:get/src/navigation/routes/bindings_interface.dart'; |
3 | import 'custom_transition.dart'; | 3 | import 'custom_transition.dart'; |
4 | import 'transitions_type.dart'; | 4 | import 'transitions_type.dart'; |
5 | 5 |
@@ -375,11 +375,12 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -375,11 +375,12 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
375 | child: SafeArea( | 375 | child: SafeArea( |
376 | minimum: widget.snackPosition == SnackPosition.BOTTOM | 376 | minimum: widget.snackPosition == SnackPosition.BOTTOM |
377 | ? EdgeInsets.only( | 377 | ? EdgeInsets.only( |
378 | - bottom: (GetUtils.isGreaterThan( | ||
379 | - MediaQuery.of(context).viewInsets.bottom, | ||
380 | - MediaQuery.of(context).padding.bottom) | ||
381 | - ? MediaQuery.of(context).viewInsets.bottom | ||
382 | - : MediaQuery.of(context).padding.bottom)) | 378 | + // bottom: (GetUtils.isGreaterThan( |
379 | + // MediaQuery.of(context).viewInsets.bottom, | ||
380 | + // MediaQuery.of(context).padding.bottom) | ||
381 | + // ? MediaQuery.of(context).viewInsets.bottom | ||
382 | + // : MediaQuery.of(context).padding.bottom)) | ||
383 | + bottom: MediaQuery.of(context).viewInsets.bottom) | ||
383 | : EdgeInsets.only(top: MediaQuery.of(context).padding.top), | 384 | : EdgeInsets.only(top: MediaQuery.of(context).padding.top), |
384 | bottom: widget.snackPosition == SnackPosition.BOTTOM, | 385 | bottom: widget.snackPosition == SnackPosition.BOTTOM, |
385 | top: widget.snackPosition == SnackPosition.TOP, | 386 | top: widget.snackPosition == SnackPosition.TOP, |
@@ -2,7 +2,7 @@ import 'dart:async'; | @@ -2,7 +2,7 @@ import 'dart:async'; | ||
2 | 2 | ||
3 | import 'package:flutter/widgets.dart'; | 3 | import 'package:flutter/widgets.dart'; |
4 | import 'package:get/src/instance/get_instance.dart'; | 4 | import 'package:get/src/instance/get_instance.dart'; |
5 | -import 'package:get/src/root/smart_management.dart'; | 5 | +import 'package:get/src/navigation/root/smart_management.dart'; |
6 | import 'rx_impl.dart'; | 6 | import 'rx_impl.dart'; |
7 | import 'rx_interface.dart'; | 7 | import 'rx_interface.dart'; |
8 | 8 | ||
@@ -63,9 +63,10 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -63,9 +63,10 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
63 | controller?.onStart(); | 63 | controller?.onStart(); |
64 | } | 64 | } |
65 | if (widget.initState != null) widget.initState(this); | 65 | if (widget.initState != null) widget.initState(this); |
66 | - // if (isCreator && GetConfig.smartManagement == SmartManagement.onlyBuilder) { | ||
67 | - // controller?.onStart(); | ||
68 | - // } | 66 | + if (widget.global && |
67 | + GetConfig.smartManagement == SmartManagement.onlyBuilder) { | ||
68 | + controller?.onStart(); | ||
69 | + } | ||
69 | subs = _observer.subject.stream.listen((data) => setState(() {})); | 70 | subs = _observer.subject.stream.listen((data) => setState(() {})); |
70 | super.initState(); | 71 | super.initState(); |
71 | } | 72 | } |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | import 'package:flutter/scheduler.dart'; | 2 | import 'package:flutter/scheduler.dart'; |
3 | -import 'package:get/src/rx/rx_callbacks.dart'; | 3 | +import 'package:get/src/state_manager/rx/rx_callbacks.dart'; |
4 | 4 | ||
5 | abstract class RxInterface<T> { | 5 | abstract class RxInterface<T> { |
6 | RxInterface([T initial]); | 6 | RxInterface([T initial]); |
@@ -21,6 +21,8 @@ abstract class RxInterface<T> { | @@ -21,6 +21,8 @@ abstract class RxInterface<T> { | ||
21 | StreamSubscription<T> listen(ValueCallback<T> callback); | 21 | StreamSubscription<T> listen(ValueCallback<T> callback); |
22 | } | 22 | } |
23 | 23 | ||
24 | +abstract class GetxService extends DisposableInterface {} | ||
25 | + | ||
24 | abstract class DisposableInterface { | 26 | abstract class DisposableInterface { |
25 | /// Called at the exact moment that the widget is allocated in memory. | 27 | /// Called at the exact moment that the widget is allocated in memory. |
26 | /// Do not overwrite this method. | 28 | /// Do not overwrite this method. |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | -import 'package:get/src/rx/rx_interface.dart'; | 2 | +import 'package:get/src/state_manager/rx/rx_interface.dart'; |
3 | import 'rx_impl.dart'; | 3 | import 'rx_impl.dart'; |
4 | 4 | ||
5 | Widget obx(Widget Function() builder) { | 5 | Widget obx(Widget Function() builder) { |
1 | import 'dart:collection'; | 1 | import 'dart:collection'; |
2 | import 'package:flutter/widgets.dart'; | 2 | import 'package:flutter/widgets.dart'; |
3 | import 'package:get/src/instance/get_instance.dart'; | 3 | import 'package:get/src/instance/get_instance.dart'; |
4 | -import 'package:get/src/root/smart_management.dart'; | ||
5 | -import 'package:get/src/rx/rx_interface.dart'; | 4 | +import 'package:get/src/navigation/root/smart_management.dart'; |
5 | +import 'package:get/src/state_manager/rx/rx_interface.dart'; | ||
6 | 6 | ||
7 | class GetxController extends DisposableInterface { | 7 | class GetxController extends DisposableInterface { |
8 | final HashSet<UpdaterBuilder> _updaters = HashSet<UpdaterBuilder>(); | 8 | final HashSet<UpdaterBuilder> _updaters = HashSet<UpdaterBuilder>(); |
@@ -97,7 +97,8 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | @@ -97,7 +97,8 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
97 | controller?.onStart(); | 97 | controller?.onStart(); |
98 | } | 98 | } |
99 | 99 | ||
100 | - if (isCreator && GetConfig.smartManagement == SmartManagement.onlyBuilder) { | 100 | + if (widget.global && |
101 | + GetConfig.smartManagement == SmartManagement.onlyBuilder) { | ||
101 | controller?.onStart(); | 102 | controller?.onStart(); |
102 | } | 103 | } |
103 | } | 104 | } |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | import 'package:get/src/instance/get_instance.dart'; | 2 | import 'package:get/src/instance/get_instance.dart'; |
3 | 3 | ||
4 | -abstract class GetWidget<T> extends StatelessWidget { | ||
5 | - const GetWidget({Key key}) : super(key: key); | ||
6 | - T get controller => GetInstance().find(); | 4 | +abstract class GetView<T> extends StatelessWidget { |
5 | + const GetView({Key key}) : super(key: key); | ||
6 | + T get controller => GetInstance().find<T>(); | ||
7 | 7 | ||
8 | @override | 8 | @override |
9 | Widget build(BuildContext context); | 9 | Widget build(BuildContext context); |
10 | } | 10 | } |
11 | 11 | ||
12 | -abstract class GetView<T> extends StatelessWidget { | ||
13 | - const GetView({Key key}) : super(key: key); | ||
14 | - T get controller => GetInstance().find(); | 12 | +abstract class GetWidget<T> extends StatelessWidget { |
13 | + GetWidget({Key key}) : super(key: key); | ||
14 | + | ||
15 | + final Set<T> _value = Set<T>(); | ||
16 | + | ||
17 | + T get controller { | ||
18 | + if (_value.isEmpty) _value.add(GetInstance().find<T>()); | ||
19 | + return _value.first; | ||
20 | + } | ||
15 | 21 | ||
16 | @override | 22 | @override |
17 | Widget build(BuildContext context); | 23 | Widget build(BuildContext context); |
1 | +// import 'package:flutter/foundation.dart'; | ||
2 | +// import 'package:flutter/material.dart'; | ||
3 | +// import 'package:get/src/instance/get_instance.dart'; | ||
4 | +// import 'package:get/state_manager.dart'; | ||
5 | + | ||
6 | +// abstract class GetState<T> extends DisposableInterface { | ||
7 | +// GetState(this.initialValue) { | ||
8 | +// _state = initialValue; | ||
9 | +// } | ||
10 | + | ||
11 | +// final Set<StateSetter> _updaters = Set<StateSetter>(); | ||
12 | + | ||
13 | +// @protected | ||
14 | +// void update(T value, [bool condition = true]) { | ||
15 | +// if (!condition) return; | ||
16 | +// _state = value; | ||
17 | +// _updaters.forEach((rs) => rs(() {})); | ||
18 | +// } | ||
19 | + | ||
20 | +// T _state; | ||
21 | + | ||
22 | +// final T initialValue; | ||
23 | + | ||
24 | +// void addListener(StateSetter value) { | ||
25 | +// _updaters.add(value); | ||
26 | +// } | ||
27 | + | ||
28 | +// void removeListener(StateSetter value) { | ||
29 | +// _updaters.add(value); | ||
30 | +// } | ||
31 | + | ||
32 | +// // @protected | ||
33 | +// T get state => _state; | ||
34 | + | ||
35 | +// @protected | ||
36 | +// void updater(void fn(T value)) { | ||
37 | +// fn(_state); | ||
38 | +// update(_state); | ||
39 | +// } | ||
40 | +// } | ||
41 | + | ||
42 | +// class StateBuilder<T extends GetState> extends StatefulWidget { | ||
43 | +// final Widget Function(dynamic) builder; | ||
44 | +// final bool global; | ||
45 | +// final String tag; | ||
46 | +// final bool autoRemove; | ||
47 | +// final bool assignId; | ||
48 | +// final void Function(State state) initState, dispose, didChangeDependencies; | ||
49 | +// final void Function(StateBuilder oldWidget, State state) didUpdateWidget; | ||
50 | +// final T Function() state; | ||
51 | +// const StateBuilder({ | ||
52 | +// Key key, | ||
53 | +// this.state, | ||
54 | +// this.global = true, | ||
55 | +// @required this.builder, | ||
56 | +// this.autoRemove = true, | ||
57 | +// this.assignId = false, | ||
58 | +// this.initState, | ||
59 | +// this.tag, | ||
60 | +// this.dispose, | ||
61 | +// this.didChangeDependencies, | ||
62 | +// this.didUpdateWidget, | ||
63 | +// }) : assert(builder != null), | ||
64 | +// super(key: key); | ||
65 | +// @override | ||
66 | +// _StateBuilderState<T> createState() => _StateBuilderState<T>(); | ||
67 | +// } | ||
68 | + | ||
69 | +// class _StateBuilderState<T extends GetState> extends State<StateBuilder<T>> { | ||
70 | +// T controller; | ||
71 | + | ||
72 | +// bool isCreator = false; | ||
73 | +// @override | ||
74 | +// void initState() { | ||
75 | +// super.initState(); | ||
76 | +// if (widget.initState != null) widget.initState(this); | ||
77 | +// if (widget.global) { | ||
78 | +// final isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); | ||
79 | +// final isRegistred = GetInstance().isRegistred<T>(tag: widget.tag); | ||
80 | + | ||
81 | +// if (isPrepared) { | ||
82 | +// isCreator = true; | ||
83 | +// } else if (isRegistred) { | ||
84 | +// isCreator = false; | ||
85 | +// } else { | ||
86 | +// isCreator = true; | ||
87 | +// } | ||
88 | + | ||
89 | +// if (isCreator) { | ||
90 | +// controller?.onStart(); | ||
91 | +// } | ||
92 | + | ||
93 | +// final instance = GetInstance().putOrFind(widget.state, tag: widget.tag); | ||
94 | +// controller = instance; | ||
95 | +// controller._updaters.add(setState); | ||
96 | +// } else { | ||
97 | +// controller = widget.state(); | ||
98 | +// isCreator = true; | ||
99 | +// controller._updaters.add(setState); | ||
100 | +// controller?.onStart(); | ||
101 | +// } | ||
102 | +// } | ||
103 | + | ||
104 | +// @override | ||
105 | +// void dispose() { | ||
106 | +// super.dispose(); | ||
107 | +// if (widget.dispose != null) widget.dispose(this); | ||
108 | +// if (isCreator || widget.assignId) { | ||
109 | +// if (widget.autoRemove && GetInstance().isRegistred<T>(tag: widget.tag)) { | ||
110 | +// controller._updaters.remove(setState); | ||
111 | +// GetInstance().delete<T>(tag: widget.tag); | ||
112 | +// } | ||
113 | +// } else { | ||
114 | +// controller._updaters.remove(setState); | ||
115 | +// } | ||
116 | +// } | ||
117 | + | ||
118 | +// @override | ||
119 | +// void didChangeDependencies() { | ||
120 | +// super.didChangeDependencies(); | ||
121 | +// if (widget.didChangeDependencies != null) { | ||
122 | +// widget.didChangeDependencies(this); | ||
123 | +// } | ||
124 | +// } | ||
125 | + | ||
126 | +// @override | ||
127 | +// void didUpdateWidget(StateBuilder oldWidget) { | ||
128 | +// super.didUpdateWidget(oldWidget as StateBuilder<T>); | ||
129 | +// if (widget.didUpdateWidget != null) widget.didUpdateWidget(oldWidget, this); | ||
130 | +// } | ||
131 | + | ||
132 | +// @override | ||
133 | +// Widget build(BuildContext context) { | ||
134 | +// return widget.builder(controller.state); | ||
135 | +// } | ||
136 | +// } |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | -import 'package:get/src/rx/rx_obx.dart'; | 2 | +import 'package:get/src/state_manager/rx/rx_obx.dart'; |
3 | import 'get_state.dart'; | 3 | import 'get_state.dart'; |
4 | 4 | ||
5 | class MixinBuilder<T extends GetxController> extends StatelessWidget { | 5 | class MixinBuilder<T extends GetxController> extends StatelessWidget { |
lib/src/state_manager/state_manager.dart
0 → 100644
1 | +export 'simple/get_state.dart'; | ||
2 | +export 'simple/immutable_state.dart'; | ||
3 | +export 'simple/get_view.dart'; | ||
4 | +export 'simple/mixin_state.dart'; | ||
5 | +export 'rx/rx_interface.dart'; | ||
6 | +export 'rx/rx_impl.dart'; | ||
7 | +export 'rx/rx_event.dart'; | ||
8 | +export 'rx/rx_obx.dart'; | ||
9 | +export 'rx/rx_getbuilder.dart'; |
lib/src/typedefs/typedefs.dart
deleted
100644 → 0
1 | -typedef FcBuilderFunc<S> = S Function(); | ||
2 | - | ||
3 | -typedef FcBuilderFuncAsync<S> = Future<S> Function(); | ||
4 | - | ||
5 | -class FcBuilder<S> { | ||
6 | - bool isSingleton; | ||
7 | - FcBuilderFunc builderFunc; | ||
8 | - S dependency; | ||
9 | - bool permanent = false; | ||
10 | - | ||
11 | - FcBuilder(this.isSingleton, this.builderFunc, this.permanent); | ||
12 | - | ||
13 | - S getSependency() { | ||
14 | - if (isSingleton) { | ||
15 | - if (dependency == null) { | ||
16 | - dependency = builderFunc() as S; | ||
17 | - } | ||
18 | - return dependency; | ||
19 | - } else { | ||
20 | - return builderFunc() as S; | ||
21 | - } | ||
22 | - } | ||
23 | -} |
1 | +import 'package:flutter/material.dart'; | ||
1 | import 'package:flutter/widgets.dart'; | 2 | import 'package:flutter/widgets.dart'; |
2 | 3 | ||
3 | -extension MDQ on BuildContext { | 4 | +extension ContextExtensionss on BuildContext { |
4 | /// The same of [MediaQuery.of(context).size] | 5 | /// The same of [MediaQuery.of(context).size] |
5 | Size get mediaQuerySize => MediaQuery.of(this).size; | 6 | Size get mediaQuerySize => MediaQuery.of(this).size; |
6 | 7 | ||
@@ -52,8 +53,17 @@ extension MDQ on BuildContext { | @@ -52,8 +53,17 @@ extension MDQ on BuildContext { | ||
52 | } | 53 | } |
53 | 54 | ||
54 | /// similar to [MediaQuery.of(context).padding] | 55 | /// similar to [MediaQuery.of(context).padding] |
56 | + ThemeData get theme => Theme.of(this); | ||
57 | + | ||
58 | + /// similar to [MediaQuery.of(context).padding] | ||
59 | + TextTheme get textTheme => Theme.of(this).textTheme; | ||
60 | + | ||
61 | + /// similar to [MediaQuery.of(context).padding] | ||
55 | EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding; | 62 | EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding; |
56 | 63 | ||
64 | + /// similar to [MediaQuery.of(context).padding] | ||
65 | + MediaQueryData get mediaQuery => MediaQuery.of(this); | ||
66 | + | ||
57 | /// similar to [MediaQuery.of(context).viewPadding] | 67 | /// similar to [MediaQuery.of(context).viewPadding] |
58 | EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding; | 68 | EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding; |
59 | 69 |
@@ -53,19 +53,22 @@ extension GetNumUtils on num { | @@ -53,19 +53,22 @@ extension GetNumUtils on num { | ||
53 | } | 53 | } |
54 | 54 | ||
55 | extension GetDynamicUtils on dynamic { | 55 | extension GetDynamicUtils on dynamic { |
56 | + /// It's This is overloading the IDE's options. Only the most useful and popular options will stay here. | ||
57 | + | ||
56 | bool get isNull => GetUtils.isNull(this); | 58 | bool get isNull => GetUtils.isNull(this); |
57 | bool get isNullOrBlank => GetUtils.isNullOrBlank(this); | 59 | bool get isNullOrBlank => GetUtils.isNullOrBlank(this); |
58 | - bool get isOneAKind => GetUtils.isOneAKind(this); | ||
59 | - bool isLengthLowerThan(int maxLength) => | ||
60 | - GetUtils.isLengthLowerThan(this, maxLength); | ||
61 | - bool isLengthGreaterThan(int maxLength) => | ||
62 | - GetUtils.isLengthGreaterThan(this, maxLength); | ||
63 | - bool isLengthGreaterOrEqual(int maxLength) => | ||
64 | - GetUtils.isLengthGreaterOrEqual(this, maxLength); | ||
65 | - bool isLengthLowerOrEqual(int maxLength) => | ||
66 | - GetUtils.isLengthLowerOrEqual(this, maxLength); | ||
67 | - bool isLengthEqualTo(int maxLength) => | ||
68 | - GetUtils.isLengthEqualTo(this, maxLength); | ||
69 | - bool isLengthBetween(int minLength, int maxLength) => | ||
70 | - GetUtils.isLengthBetween(this, minLength, maxLength); | 60 | + |
61 | + // bool get isOneAKind => GetUtils.isOneAKind(this); | ||
62 | + // bool isLengthLowerThan(int maxLength) => | ||
63 | + // GetUtils.isLengthLowerThan(this, maxLength); | ||
64 | + // bool isLengthGreaterThan(int maxLength) => | ||
65 | + // GetUtils.isLengthGreaterThan(this, maxLength); | ||
66 | + // bool isLengthGreaterOrEqual(int maxLength) => | ||
67 | + // GetUtils.isLengthGreaterOrEqual(this, maxLength); | ||
68 | + // bool isLengthLowerOrEqual(int maxLength) => | ||
69 | + // GetUtils.isLengthLowerOrEqual(this, maxLength); | ||
70 | + // bool isLengthEqualTo(int maxLength) => | ||
71 | + // GetUtils.isLengthEqualTo(this, maxLength); | ||
72 | + // bool isLengthBetween(int minLength, int maxLength) => | ||
73 | + // GetUtils.isLengthBetween(this, minLength, maxLength); | ||
71 | } | 74 | } |
lib/src/utils/utils.dart
0 → 100644
lib/state_manager.dart
deleted
100644 → 0
lib/utils.dart
deleted
100644 → 0
@@ -21,7 +21,7 @@ packages: | @@ -21,7 +21,7 @@ packages: | ||
21 | name: characters | 21 | name: characters |
22 | url: "https://pub.dartlang.org" | 22 | url: "https://pub.dartlang.org" |
23 | source: hosted | 23 | source: hosted |
24 | - version: "1.0.0" | 24 | + version: "1.1.0-nullsafety" |
25 | charcode: | 25 | charcode: |
26 | dependency: transitive | 26 | dependency: transitive |
27 | description: | 27 | description: |
@@ -42,7 +42,7 @@ packages: | @@ -42,7 +42,7 @@ packages: | ||
42 | name: collection | 42 | name: collection |
43 | url: "https://pub.dartlang.org" | 43 | url: "https://pub.dartlang.org" |
44 | source: hosted | 44 | source: hosted |
45 | - version: "1.14.13" | 45 | + version: "1.15.0-nullsafety" |
46 | fake_async: | 46 | fake_async: |
47 | dependency: transitive | 47 | dependency: transitive |
48 | description: | 48 | description: |
@@ -73,7 +73,7 @@ packages: | @@ -73,7 +73,7 @@ packages: | ||
73 | name: meta | 73 | name: meta |
74 | url: "https://pub.dartlang.org" | 74 | url: "https://pub.dartlang.org" |
75 | source: hosted | 75 | source: hosted |
76 | - version: "1.1.8" | 76 | + version: "1.3.0-nullsafety" |
77 | path: | 77 | path: |
78 | dependency: transitive | 78 | dependency: transitive |
79 | description: | 79 | description: |
@@ -134,13 +134,13 @@ packages: | @@ -134,13 +134,13 @@ packages: | ||
134 | name: typed_data | 134 | name: typed_data |
135 | url: "https://pub.dartlang.org" | 135 | url: "https://pub.dartlang.org" |
136 | source: hosted | 136 | source: hosted |
137 | - version: "1.2.0" | 137 | + version: "1.3.0-nullsafety" |
138 | vector_math: | 138 | vector_math: |
139 | dependency: transitive | 139 | dependency: transitive |
140 | description: | 140 | description: |
141 | name: vector_math | 141 | name: vector_math |
142 | url: "https://pub.dartlang.org" | 142 | url: "https://pub.dartlang.org" |
143 | source: hosted | 143 | source: hosted |
144 | - version: "2.0.8" | 144 | + version: "2.1.0-nullsafety" |
145 | sdks: | 145 | sdks: |
146 | - dart: ">=2.9.0-14.0.dev <3.0.0" | 146 | + dart: ">=2.9.0-18.0 <2.9.0" |
1 | name: get | 1 | name: get |
2 | -description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. | ||
3 | -version: 3.4.0 | 2 | +description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX. |
3 | +version: 3.4.1 | ||
4 | homepage: https://github.com/jonataslaw/get | 4 | homepage: https://github.com/jonataslaw/get |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment