Jonatas

improve testMode

  1 +## [3.12.2]
  2 +- Fix typos on code and docs (@wbemanuel and @Goddchen)
  3 +- Improve: typedef to GetBuilder and Getx widgets
  4 +- Improve behaviour of null route on lastest flutter version (@FiercestT)
  5 +- Fix onReady called twice on smartManagement.onlyBuilders
  6 +- Fix onClose called twice when GetBuilder is used
  7 +- Fix default customTransitions, and defaultDuration be ignored on unnamedRoutes
  8 +- Transition.native use default Flutter transitions
  9 +- Added Get.testMode to use contextless elements on unit tests
  10 +- Added Get.appUpdate and improve Get.forceAppUpdate
  11 +-
  12 +
1 ## [3.12.1] 13 ## [3.12.1]
2 - Remove spaces whitespaces from dart files 14 - Remove spaces whitespaces from dart files
3 15
@@ -945,13 +945,27 @@ extension GetNavigation on GetInterface { @@ -945,13 +945,27 @@ extension GetNavigation on GetInterface {
945 } 945 }
946 946
947 GlobalKey<NavigatorState> global(int k) { 947 GlobalKey<NavigatorState> global(int k) {
  948 + GlobalKey<NavigatorState> _key;
948 if (k == null) { 949 if (k == null) {
949 - return key; 950 + _key = key;
950 } 951 }
951 if (!keys.containsKey(k)) { 952 if (!keys.containsKey(k)) {
952 throw 'Route id ($k) not found'; 953 throw 'Route id ($k) not found';
  954 + } else {
  955 + _key = keys[k];
  956 + }
  957 +
  958 + if (_key.currentContext == null) {
  959 + throw """You are trying to use contextless navigation without
  960 + a GetMaterialApp or Get.key.
  961 + If you are testing your app, you can use:
  962 + [Get.testMode = true], or if you are running your app on
  963 + a physical device or emulator, you must exchange your [MaterialApp]
  964 + for a [GetMaterialApp].
  965 + """;
953 } 966 }
954 - return keys[k]; 967 +
  968 + return _key;
955 } 969 }
956 970
957 @Deprecated(''' 971 @Deprecated('''
@@ -993,9 +1007,6 @@ Since version 2.8 it is possible to access the properties @@ -993,9 +1007,6 @@ Since version 2.8 it is possible to access the properties
993 /// give access to current Overlay Context 1007 /// give access to current Overlay Context
994 BuildContext get overlayContext => key?.currentState?.overlay?.context; 1008 BuildContext get overlayContext => key?.currentState?.overlay?.context;
995 1009
996 - /// give access to current Overlay Context  
997 - BuildContext get overlayState => key?.currentState?.overlay?.context;  
998 -  
999 /// give access to Theme.of(context) 1010 /// give access to Theme.of(context)
1000 ThemeData get theme { 1011 ThemeData get theme {
1001 ThemeData _theme; 1012 ThemeData _theme;
@@ -1032,15 +1043,7 @@ Since version 2.8 it is possible to access the properties @@ -1032,15 +1043,7 @@ Since version 2.8 it is possible to access the properties
1032 1043
1033 GlobalKey<NavigatorState> get key { 1044 GlobalKey<NavigatorState> get key {
1034 final _key = getxController?.key; 1045 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 - } 1046 +
1044 return _key; 1047 return _key;
1045 } 1048 }
1046 1049