Jonatas

added testMode

@@ -53,7 +53,7 @@ extension GetNavigation on GetInterface { @@ -53,7 +53,7 @@ extension GetNavigation on GetInterface {
53 if (preventDuplicates && routeName == currentRoute) { 53 if (preventDuplicates && routeName == currentRoute) {
54 return null; 54 return null;
55 } 55 }
56 - return global(id).currentState.push( 56 + return global(id)?.currentState?.push(
57 GetPageRoute( 57 GetPageRoute(
58 opaque: opaque ?? true, 58 opaque: opaque ?? true,
59 page: () => page, 59 page: () => page,
@@ -97,7 +97,7 @@ extension GetNavigation on GetInterface { @@ -97,7 +97,7 @@ extension GetNavigation on GetInterface {
97 if (preventDuplicates && page == currentRoute) { 97 if (preventDuplicates && page == currentRoute) {
98 return null; 98 return null;
99 } 99 }
100 - return global(id).currentState.pushNamed(page, arguments: arguments); 100 + return global(id)?.currentState?.pushNamed(page, arguments: arguments);
101 } 101 }
102 102
103 /// **Navigation.pushReplacementNamed()** shortcut.<br><br> 103 /// **Navigation.pushReplacementNamed()** shortcut.<br><br>
@@ -126,8 +126,8 @@ extension GetNavigation on GetInterface { @@ -126,8 +126,8 @@ extension GetNavigation on GetInterface {
126 return null; 126 return null;
127 } 127 }
128 return global(id) 128 return global(id)
129 - .currentState  
130 - .pushReplacementNamed(page, arguments: arguments); 129 + ?.currentState
  130 + ?.pushReplacementNamed(page, arguments: arguments);
131 } 131 }
132 132
133 /// **Navigation.popUntil()** shortcut.<br><br> 133 /// **Navigation.popUntil()** shortcut.<br><br>
@@ -146,7 +146,7 @@ extension GetNavigation on GetInterface { @@ -146,7 +146,7 @@ extension GetNavigation on GetInterface {
146 void until(RoutePredicate predicate, {int id}) { 146 void until(RoutePredicate predicate, {int id}) {
147 // if (key.currentState.mounted) // add this if appear problems on future with route navigate 147 // if (key.currentState.mounted) // add this if appear problems on future with route navigate
148 // when widget don't mounted 148 // when widget don't mounted
149 - return global(id).currentState.popUntil(predicate); 149 + return global(id)?.currentState?.popUntil(predicate);
150 } 150 }
151 151
152 /// **Navigation.pushAndRemoveUntil()** shortcut.<br><br> 152 /// **Navigation.pushAndRemoveUntil()** shortcut.<br><br>
@@ -170,7 +170,7 @@ extension GetNavigation on GetInterface { @@ -170,7 +170,7 @@ extension GetNavigation on GetInterface {
170 Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { 170 Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) {
171 // if (key.currentState.mounted) // add this if appear problems on future with route navigate 171 // if (key.currentState.mounted) // add this if appear problems on future with route navigate
172 // when widget don't mounted 172 // when widget don't mounted
173 - return global(id).currentState.pushAndRemoveUntil(page, predicate); 173 + return global(id)?.currentState?.pushAndRemoveUntil(page, predicate);
174 } 174 }
175 175
176 /// **Navigation.pushNamedAndRemoveUntil()** shortcut.<br><br> 176 /// **Navigation.pushNamedAndRemoveUntil()** shortcut.<br><br>
@@ -197,8 +197,8 @@ extension GetNavigation on GetInterface { @@ -197,8 +197,8 @@ extension GetNavigation on GetInterface {
197 dynamic arguments, 197 dynamic arguments,
198 }) { 198 }) {
199 return global(id) 199 return global(id)
200 - .currentState  
201 - .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); 200 + ?.currentState
  201 + ?.pushNamedAndRemoveUntil(page, predicate, arguments: arguments);
202 } 202 }
203 203
204 /// **Navigation.popAndPushNamed()** shortcut.<br><br> 204 /// **Navigation.popAndPushNamed()** shortcut.<br><br>
@@ -219,8 +219,8 @@ extension GetNavigation on GetInterface { @@ -219,8 +219,8 @@ extension GetNavigation on GetInterface {
219 dynamic result, 219 dynamic result,
220 }) { 220 }) {
221 return global(id) 221 return global(id)
222 - .currentState  
223 - .popAndPushNamed(page, arguments: arguments, result: result); 222 + ?.currentState
  223 + ?.popAndPushNamed(page, arguments: arguments, result: result);
224 } 224 }
225 225
226 /// **Navigation.removeRoute()** shortcut.<br><br> 226 /// **Navigation.removeRoute()** shortcut.<br><br>
@@ -230,7 +230,7 @@ extension GetNavigation on GetInterface { @@ -230,7 +230,7 @@ extension GetNavigation on GetInterface {
230 /// [id] is for when you are using nested navigation, 230 /// [id] is for when you are using nested navigation,
231 /// as explained in documentation 231 /// as explained in documentation
232 void removeRoute(Route<dynamic> route, {int id}) { 232 void removeRoute(Route<dynamic> route, {int id}) {
233 - return global(id).currentState.removeRoute(route); 233 + return global(id)?.currentState?.removeRoute(route);
234 } 234 }
235 235
236 /// **Navigation.pushNamedAndRemoveUntil()** shortcut.<br><br> 236 /// **Navigation.pushNamedAndRemoveUntil()** shortcut.<br><br>
@@ -259,7 +259,7 @@ extension GetNavigation on GetInterface { @@ -259,7 +259,7 @@ extension GetNavigation on GetInterface {
259 dynamic arguments, 259 dynamic arguments,
260 int id, 260 int id,
261 }) { 261 }) {
262 - return global(id).currentState.pushNamedAndRemoveUntil( 262 + return global(id)?.currentState?.pushNamedAndRemoveUntil(
263 newRouteName, 263 newRouteName,
264 predicate ?? (_) => false, 264 predicate ?? (_) => false,
265 arguments: arguments, 265 arguments: arguments,
@@ -293,16 +293,16 @@ extension GetNavigation on GetInterface { @@ -293,16 +293,16 @@ extension GetNavigation on GetInterface {
293 int id, 293 int id,
294 }) { 294 }) {
295 if (closeOverlays && isOverlaysOpen) { 295 if (closeOverlays && isOverlaysOpen) {
296 - navigator.popUntil((route) { 296 + navigator?.popUntil((route) {
297 return (isOverlaysClosed); 297 return (isOverlaysClosed);
298 }); 298 });
299 } 299 }
300 if (canPop) { 300 if (canPop) {
301 - if (global(id).currentState.canPop()) {  
302 - global(id).currentState.pop(result); 301 + if (global(id)?.currentState?.canPop() == true) {
  302 + global(id)?.currentState?.pop(result);
303 } 303 }
304 } else { 304 } else {
305 - global(id).currentState.pop(result); 305 + global(id)?.currentState?.pop(result);
306 } 306 }
307 } 307 }
308 308
@@ -317,7 +317,7 @@ extension GetNavigation on GetInterface { @@ -317,7 +317,7 @@ extension GetNavigation on GetInterface {
317 times = 1; 317 times = 1;
318 } 318 }
319 var count = 0; 319 var count = 0;
320 - var back = global(id).currentState.popUntil((route) => count++ == times); 320 + var back = global(id)?.currentState?.popUntil((route) => count++ == times);
321 321
322 return back; 322 return back;
323 } 323 }
@@ -364,7 +364,7 @@ extension GetNavigation on GetInterface { @@ -364,7 +364,7 @@ extension GetNavigation on GetInterface {
364 if (preventDuplicates && routeName == currentRoute) { 364 if (preventDuplicates && routeName == currentRoute) {
365 return null; 365 return null;
366 } 366 }
367 - return global(id).currentState.pushReplacement(GetPageRoute( 367 + return global(id)?.currentState?.pushReplacement(GetPageRoute(
368 opaque: opaque ?? true, 368 opaque: opaque ?? true,
369 page: () => page, 369 page: () => page,
370 binding: binding, 370 binding: binding,
@@ -423,7 +423,7 @@ extension GetNavigation on GetInterface { @@ -423,7 +423,7 @@ extension GetNavigation on GetInterface {
423 }) { 423 }) {
424 var routeName = "/${page.runtimeType.toString()}"; 424 var routeName = "/${page.runtimeType.toString()}";
425 425
426 - return global(id).currentState.pushAndRemoveUntil( 426 + return global(id)?.currentState?.pushAndRemoveUntil(
427 GetPageRoute( 427 GetPageRoute(
428 opaque: opaque ?? true, 428 opaque: opaque ?? true,
429 popGesture: popGesture ?? defaultPopGesture, 429 popGesture: popGesture ?? defaultPopGesture,
@@ -754,7 +754,7 @@ extension GetNavigation on GetInterface { @@ -754,7 +754,7 @@ extension GetNavigation on GetInterface {
754 } 754 }
755 755
756 Future<T> showSnackbar<T>(GetBar snackbar) { 756 Future<T> showSnackbar<T>(GetBar snackbar) {
757 - return key.currentState.push(SnackRoute<T>(snack: snackbar)); 757 + return key?.currentState?.push(SnackRoute<T>(snack: snackbar));
758 } 758 }
759 759
760 void snackbar( 760 void snackbar(
@@ -806,7 +806,7 @@ extension GetNavigation on GetInterface { @@ -806,7 +806,7 @@ extension GetNavigation on GetInterface {
806 Text( 806 Text(
807 title, 807 title,
808 style: TextStyle( 808 style: TextStyle(
809 - color: colorText ?? theme.iconTheme.color, 809 + color: colorText ?? iconColor ?? Colors.black,
810 fontWeight: FontWeight.w800, 810 fontWeight: FontWeight.w800,
811 fontSize: 16, 811 fontSize: 16,
812 ), 812 ),
@@ -815,7 +815,7 @@ extension GetNavigation on GetInterface { @@ -815,7 +815,7 @@ extension GetNavigation on GetInterface {
815 Text( 815 Text(
816 message, 816 message,
817 style: TextStyle( 817 style: TextStyle(
818 - color: colorText ?? theme.iconTheme.color, 818 + color: colorText ?? iconColor ?? Colors.black,
819 fontWeight: FontWeight.w300, 819 fontWeight: FontWeight.w300,
820 fontSize: 14, 820 fontSize: 14,
821 ), 821 ),
@@ -852,11 +852,11 @@ extension GetNavigation on GetInterface { @@ -852,11 +852,11 @@ extension GetNavigation on GetInterface {
852 userInputForm: userInputForm); 852 userInputForm: userInputForm);
853 853
854 if (instantInit) { 854 if (instantInit) {
855 - getBar.show(); 855 + showSnackbar(getBar);
856 } else { 856 } else {
857 routing.isSnackbar = true; 857 routing.isSnackbar = true;
858 SchedulerBinding.instance.addPostFrameCallback((_) { 858 SchedulerBinding.instance.addPostFrameCallback((_) {
859 - getBar.show(); 859 + showSnackbar(getBar);
860 }); 860 });
861 } 861 }
862 } 862 }
@@ -988,16 +988,25 @@ Since version 2.8 it is possible to access the properties @@ -988,16 +988,25 @@ Since version 2.8 it is possible to access the properties
988 bool get isOpaqueRouteDefault => defaultOpaqueRoute; 988 bool get isOpaqueRouteDefault => defaultOpaqueRoute;
989 989
990 /// give access to currentContext 990 /// give access to currentContext
991 - BuildContext get context => key.currentContext; 991 + BuildContext get context => key?.currentContext;
992 992
993 /// give access to current Overlay Context 993 /// give access to current Overlay Context
994 - BuildContext get overlayContext => key.currentState.overlay.context; 994 + BuildContext get overlayContext => key?.currentState?.overlay?.context;
  995 +
  996 + /// give access to current Overlay Context
  997 + BuildContext get overlayState => key?.currentState?.overlay?.context;
995 998
996 /// give access to Theme.of(context) 999 /// give access to Theme.of(context)
997 - ThemeData get theme => Theme.of(context); 1000 + ThemeData get theme {
  1001 + ThemeData _theme;
  1002 + if (context != null) {
  1003 + _theme = Theme.of(context);
  1004 + }
  1005 + return _theme;
  1006 + }
998 1007
999 /// give access to TextTheme.of(context) 1008 /// give access to TextTheme.of(context)
1000 - TextTheme get textTheme => Theme.of(context).textTheme; 1009 + TextTheme get textTheme => theme?.textTheme;
1001 1010
1002 /// give access to Mediaquery.of(context) 1011 /// give access to Mediaquery.of(context)
1003 MediaQueryData get mediaQuery => MediaQuery.of(context); 1012 MediaQueryData get mediaQuery => MediaQuery.of(context);
@@ -1010,7 +1019,7 @@ Since version 2.8 it is possible to access the properties @@ -1010,7 +1019,7 @@ Since version 2.8 it is possible to access the properties
1010 (mediaQuery.platformBrightness == Brightness.dark); 1019 (mediaQuery.platformBrightness == Brightness.dark);
1011 1020
1012 /// give access to Theme.of(context).iconTheme.color 1021 /// give access to Theme.of(context).iconTheme.color
1013 - Color get iconColor => Theme.of(context).iconTheme.color; 1022 + Color get iconColor => theme?.iconTheme?.color;
1014 1023
1015 /// give access to FocusScope.of(context) 1024 /// give access to FocusScope.of(context)
1016 FocusNode get focusScope => FocusManager.instance.primaryFocus; 1025 FocusNode get focusScope => FocusManager.instance.primaryFocus;
@@ -1021,9 +1030,21 @@ Since version 2.8 it is possible to access the properties @@ -1021,9 +1030,21 @@ Since version 2.8 it is possible to access the properties
1021 /// give access to Immutable MediaQuery.of(context).size.width 1030 /// give access to Immutable MediaQuery.of(context).size.width
1022 double get width => MediaQuery.of(context).size.width; 1031 double get width => MediaQuery.of(context).size.width;
1023 1032
1024 - GlobalKey<NavigatorState> get key => getxController.key; 1033 + GlobalKey<NavigatorState> get key {
  1034 + final _key = getxController?.key;
  1035 + if (_key?.currentState == null && !testMode) {
  1036 + throw """You are trying to use contextless navigation without
  1037 + a GetMaterialApp or Get.key.
  1038 + If you are testing your app, you can use:
  1039 + [Get.testMode = true], or if you are running your app on
  1040 + a physical device or emulator, you must exchange your [MaterialApp]
  1041 + for a [GetMaterialApp].
  1042 + """;
  1043 + }
  1044 + return _key;
  1045 + }
1025 1046
1026 - Map<int, GlobalKey<NavigatorState>> get keys => getxController.keys; 1047 + Map<int, GlobalKey<NavigatorState>> get keys => getxController?.keys;
1027 1048
1028 GetMaterialController get rootController => getxController; 1049 GetMaterialController get rootController => getxController;
1029 1050
@@ -1059,6 +1080,9 @@ Since version 2.8 it is possible to access the properties @@ -1059,6 +1080,9 @@ Since version 2.8 it is possible to access the properties
1059 set customTransition(CustomTransition newTransition) => 1080 set customTransition(CustomTransition newTransition) =>
1060 getxController.customTransition = newTransition; 1081 getxController.customTransition = newTransition;
1061 1082
  1083 + bool get testMode => getxController.testMode;
  1084 + set testMode(bool isTest) => getxController.testMode = isTest;
  1085 +
1062 static GetMaterialController getxController = GetMaterialController(); 1086 static GetMaterialController getxController = GetMaterialController();
1063 } 1087 }
1064 1088
@@ -7,6 +7,7 @@ import '../routes/transitions_type.dart'; @@ -7,6 +7,7 @@ import '../routes/transitions_type.dart';
7 import 'parse_route.dart'; 7 import 'parse_route.dart';
8 8
9 class GetMaterialController extends GetxController { 9 class GetMaterialController extends GetxController {
  10 + bool testMode = false;
10 Key unikey; 11 Key unikey;
11 ThemeData theme; 12 ThemeData theme;
12 ThemeMode themeMode; 13 ThemeMode themeMode;
@@ -19,7 +20,7 @@ class GetMaterialController extends GetxController { @@ -19,7 +20,7 @@ class GetMaterialController extends GetxController {
19 Curve defaultTransitionCurve = Curves.easeOutQuad; 20 Curve defaultTransitionCurve = Curves.easeOutQuad;
20 21
21 Curve defaultDialogTransitionCurve = Curves.easeOutQuad; 22 Curve defaultDialogTransitionCurve = Curves.easeOutQuad;
22 - 23 +
23 Duration defaultDialogTransitionDuration = Duration(milliseconds: 300); 24 Duration defaultDialogTransitionDuration = Duration(milliseconds: 300);
24 25
25 final routing = Routing(); 26 final routing = Routing();
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart'; @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
4 import 'package:flutter/scheduler.dart'; 4 import 'package:flutter/scheduler.dart';
5 import 'package:get_core/get_core.dart'; 5 import 'package:get_core/get_core.dart';
6 import '../../get_navigation.dart'; 6 import '../../get_navigation.dart';
7 -import 'snack_route.dart';  
8 7
9 typedef SnackbarStatusCallback = void Function(SnackbarStatus status); 8 typedef SnackbarStatusCallback = void Function(SnackbarStatus status);
10 typedef OnTap = void Function(GetBar snack); 9 typedef OnTap = void Function(GetBar snack);
@@ -195,10 +194,10 @@ class GetBar<T extends Object> extends StatefulWidget { @@ -195,10 +194,10 @@ class GetBar<T extends Object> extends StatefulWidget {
195 /// Every other widget is ignored if this is not null. 194 /// Every other widget is ignored if this is not null.
196 final Form userInputForm; 195 final Form userInputForm;
197 196
198 - /// Show the snack. Kicks in [SnackbarStatus.OPENING] state 197 + /// Show the snack. It's call [SnackbarStatus.OPENING] state
199 /// followed by [SnackbarStatus.OPEN] 198 /// followed by [SnackbarStatus.OPEN]
200 Future<T> show<T>() async { 199 Future<T> show<T>() async {
201 - return Get.key.currentState.push(SnackRoute<T>(snack: this)); 200 + return Get.showSnackbar(this);
202 } 201 }
203 202
204 @override 203 @override