Showing
7 changed files
with
133 additions
and
83 deletions
| @@ -16,7 +16,6 @@ class MyApp extends StatelessWidget { | @@ -16,7 +16,6 @@ class MyApp extends StatelessWidget { | ||
| 16 | return GetMaterialApp( | 16 | return GetMaterialApp( |
| 17 | debugShowCheckedModeBanner: false, | 17 | debugShowCheckedModeBanner: false, |
| 18 | enableLog: true, | 18 | enableLog: true, |
| 19 | - // locale: Locale('PT'), | ||
| 20 | logWriterCallback: Logger.write, | 19 | logWriterCallback: Logger.write, |
| 21 | initialRoute: AppPages.INITIAL, | 20 | initialRoute: AppPages.INITIAL, |
| 22 | getPages: AppPages.routes, | 21 | getPages: AppPages.routes, |
| 1 | -import 'package:flutter/material.dart'; | ||
| 2 | - | ||
| 3 | -import '../../utils.dart'; | ||
| 4 | -import '../navigation/root/parse_route.dart'; | ||
| 5 | -import '../navigation/root/root_controller.dart'; | ||
| 6 | -import '../navigation/routes/custom_transition.dart'; | ||
| 7 | -import '../navigation/routes/observers/route_observer.dart'; | ||
| 8 | -import '../navigation/routes/transitions_type.dart'; | ||
| 9 | - | ||
| 10 | /// Use Get.to instead of Navigator.push, Get.off instead | 1 | /// Use Get.to instead of Navigator.push, Get.off instead |
| 11 | /// of Navigator.pushReplacement, | 2 | /// of Navigator.pushReplacement, |
| 12 | /// Get.offAll instead of Navigator.pushAndRemoveUntil. | 3 | /// Get.offAll instead of Navigator.pushAndRemoveUntil. |
| @@ -16,38 +7,4 @@ import '../navigation/routes/transitions_type.dart'; | @@ -16,38 +7,4 @@ import '../navigation/routes/transitions_type.dart'; | ||
| 16 | /// 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 |
| 17 | /// the parentheses and the magic will occur. | 8 | /// the parentheses and the magic will occur. |
| 18 | 9 | ||
| 19 | -abstract class GetInterface { | ||
| 20 | - bool defaultPopGesture = GetPlatform.isIOS; | ||
| 21 | - bool defaultOpaqueRoute = true; | ||
| 22 | - | ||
| 23 | - Transition defaultTransition; | ||
| 24 | - Duration defaultTransitionDuration = Duration(milliseconds: 400); | ||
| 25 | - Curve defaultTransitionCurve = Curves.easeOutQuad; | ||
| 26 | - | ||
| 27 | - Curve defaultDialogTransitionCurve = Curves.easeOutQuad; | ||
| 28 | - Duration defaultDialogTransitionDuration = Duration(milliseconds: 400); | ||
| 29 | - | ||
| 30 | - bool defaultGlobalState = true; | ||
| 31 | - RouteSettings settings; | ||
| 32 | - String defaultSeparator = '_'; | ||
| 33 | - | ||
| 34 | - final routing = Routing(); | ||
| 35 | - | ||
| 36 | - Map<String, String> parameters = {}; | ||
| 37 | - | ||
| 38 | - ParseRouteTree routeTree; | ||
| 39 | - | ||
| 40 | - CustomTransition customTransition; | ||
| 41 | - | ||
| 42 | - GetMaterialController getxController = GetMaterialController(); | ||
| 43 | - | ||
| 44 | - Locale locale; | ||
| 45 | - | ||
| 46 | - Locale fallbackLocale; | ||
| 47 | - | ||
| 48 | - GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); | ||
| 49 | - | ||
| 50 | - Map<int, GlobalKey<NavigatorState>> keys = {}; | ||
| 51 | - | ||
| 52 | - Map<String, Map<String, String>> translations = {}; | ||
| 53 | -} | 10 | +abstract class GetInterface {} |
| @@ -21,6 +21,8 @@ class GetInstance { | @@ -21,6 +21,8 @@ class GetInstance { | ||
| 21 | 21 | ||
| 22 | static GetInstance _getInstance; | 22 | static GetInstance _getInstance; |
| 23 | 23 | ||
| 24 | + static final config = GetConfig(); | ||
| 25 | + | ||
| 24 | /// Holds references to every registered Instance when using | 26 | /// Holds references to every registered Instance when using |
| 25 | /// [Get.put()] | 27 | /// [Get.put()] |
| 26 | static final Map<String, _InstanceBuilderFactory> _singl = {}; | 28 | static final Map<String, _InstanceBuilderFactory> _singl = {}; |
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/scheduler.dart'; | 2 | import 'package:flutter/scheduler.dart'; |
| 3 | 3 | ||
| 4 | +import '../../get.dart'; | ||
| 4 | import '../../instance_manager.dart'; | 5 | import '../../instance_manager.dart'; |
| 5 | import '../../route_manager.dart'; | 6 | import '../../route_manager.dart'; |
| 6 | import '../core/get_interface.dart'; | 7 | import '../core/get_interface.dart'; |
| 7 | import '../core/log.dart'; | 8 | import '../core/log.dart'; |
| 8 | import 'dialog/dialog_route.dart'; | 9 | import 'dialog/dialog_route.dart'; |
| 9 | import 'root/parse_route.dart'; | 10 | import 'root/parse_route.dart'; |
| 11 | +import 'root/root_controller.dart'; | ||
| 10 | import 'routes/bindings_interface.dart'; | 12 | import 'routes/bindings_interface.dart'; |
| 11 | 13 | ||
| 12 | /// It replaces the Flutter Navigator, but needs no context. | 14 | /// It replaces the Flutter Navigator, but needs no context. |
| @@ -640,6 +642,7 @@ extension GetNavigation on GetInterface { | @@ -640,6 +642,7 @@ extension GetNavigation on GetInterface { | ||
| 640 | bool useRootNavigator = false, | 642 | bool useRootNavigator = false, |
| 641 | bool isDismissible = true, | 643 | bool isDismissible = true, |
| 642 | bool enableDrag = true, | 644 | bool enableDrag = true, |
| 645 | + RouteSettings settings, | ||
| 643 | }) { | 646 | }) { |
| 644 | assert(bottomsheet != null); | 647 | assert(bottomsheet != null); |
| 645 | assert(persistent != null); | 648 | assert(persistent != null); |
| @@ -892,26 +895,22 @@ extension GetNavigation on GetInterface { | @@ -892,26 +895,22 @@ extension GetNavigation on GetInterface { | ||
| 892 | GetConfig.log = logWriterCallback; | 895 | GetConfig.log = logWriterCallback; |
| 893 | } | 896 | } |
| 894 | if (defaultPopGesture != null) { | 897 | if (defaultPopGesture != null) { |
| 895 | - this.defaultPopGesture = defaultPopGesture; | 898 | + getxController.defaultPopGesture = defaultPopGesture; |
| 896 | } | 899 | } |
| 897 | if (defaultOpaqueRoute != null) { | 900 | if (defaultOpaqueRoute != null) { |
| 898 | - this.defaultOpaqueRoute = defaultOpaqueRoute; | 901 | + getxController.defaultOpaqueRoute = defaultOpaqueRoute; |
| 899 | } | 902 | } |
| 900 | if (defaultTransition != null) { | 903 | if (defaultTransition != null) { |
| 901 | - this.defaultTransition = defaultTransition; | 904 | + getxController.defaultTransition = defaultTransition; |
| 902 | } | 905 | } |
| 903 | 906 | ||
| 904 | if (defaultDurationTransition != null) { | 907 | if (defaultDurationTransition != null) { |
| 905 | - defaultTransitionDuration = defaultDurationTransition; | ||
| 906 | - } | ||
| 907 | - | ||
| 908 | - if (defaultGlobalState != null) { | ||
| 909 | - this.defaultGlobalState = defaultGlobalState; | 908 | + getxController.defaultTransitionDuration = defaultDurationTransition; |
| 910 | } | 909 | } |
| 911 | } | 910 | } |
| 912 | 911 | ||
| 913 | void updateLocale(Locale l) { | 912 | void updateLocale(Locale l) { |
| 914 | - locale = l; | 913 | + Get.locale = l; |
| 915 | forceAppUpdate(); | 914 | forceAppUpdate(); |
| 916 | } | 915 | } |
| 917 | 916 | ||
| @@ -924,20 +923,6 @@ extension GetNavigation on GetInterface { | @@ -924,20 +923,6 @@ extension GetNavigation on GetInterface { | ||
| 924 | (context as Element).visitChildren(rebuild); | 923 | (context as Element).visitChildren(rebuild); |
| 925 | } | 924 | } |
| 926 | 925 | ||
| 927 | - void addTranslations(Map<String, Map<String, String>> tr) { | ||
| 928 | - translations.addAll(tr); | ||
| 929 | - } | ||
| 930 | - | ||
| 931 | - void appendTranslations(Map<String, Map<String, String>> tr) { | ||
| 932 | - tr.forEach((key, map) { | ||
| 933 | - if (Get.translations.containsKey(key)) { | ||
| 934 | - Get.translations[key].addAll(map); | ||
| 935 | - } else { | ||
| 936 | - Get.translations[key] = map; | ||
| 937 | - } | ||
| 938 | - }); | ||
| 939 | - } | ||
| 940 | - | ||
| 941 | void changeTheme(ThemeData theme) { | 926 | void changeTheme(ThemeData theme) { |
| 942 | getxController.setTheme(theme); | 927 | getxController.setTheme(theme); |
| 943 | } | 928 | } |
| @@ -947,7 +932,7 @@ extension GetNavigation on GetInterface { | @@ -947,7 +932,7 @@ extension GetNavigation on GetInterface { | ||
| 947 | } | 932 | } |
| 948 | 933 | ||
| 949 | GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { | 934 | GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { |
| 950 | - key = newKey; | 935 | + getxController.key = newKey; |
| 951 | return key; | 936 | return key; |
| 952 | } | 937 | } |
| 953 | 938 | ||
| @@ -966,13 +951,11 @@ extension GetNavigation on GetInterface { | @@ -966,13 +951,11 @@ extension GetNavigation on GetInterface { | ||
| 966 | return keys[k]; | 951 | return keys[k]; |
| 967 | } | 952 | } |
| 968 | 953 | ||
| 969 | - RouteSettings get routeSettings => settings; | ||
| 970 | - | ||
| 971 | - // FIXME: wouldn't a direct set suffice here? | ||
| 972 | - // ignore: use_setters_to_change_properties | ||
| 973 | - void setSettings(RouteSettings settings) { | ||
| 974 | - this.settings = settings; | ||
| 975 | - } | 954 | + @Deprecated(''' |
| 955 | +Since version 2.8 it is possible to access the properties | ||
| 956 | +[Get.arguments] and [Get.currentRoute] directly. | ||
| 957 | +[routeSettings] is useless and should not be used.''') | ||
| 958 | + RouteSettings get routeSettings => null; | ||
| 976 | 959 | ||
| 977 | /// give current arguments | 960 | /// give current arguments |
| 978 | dynamic get arguments => routing.args; | 961 | dynamic get arguments => routing.args; |
| @@ -1034,4 +1017,43 @@ extension GetNavigation on GetInterface { | @@ -1034,4 +1017,43 @@ extension GetNavigation on GetInterface { | ||
| 1034 | 1017 | ||
| 1035 | /// give access to Immutable MediaQuery.of(context).size.width | 1018 | /// give access to Immutable MediaQuery.of(context).size.width |
| 1036 | double get width => MediaQuery.of(context).size.width; | 1019 | double get width => MediaQuery.of(context).size.width; |
| 1020 | + | ||
| 1021 | + GlobalKey<NavigatorState> get key => getxController.key; | ||
| 1022 | + | ||
| 1023 | + Map<int, GlobalKey<NavigatorState>> get keys => getxController.keys; | ||
| 1024 | + | ||
| 1025 | + GetMaterialController get rootController => getxController; | ||
| 1026 | + | ||
| 1027 | + bool get defaultPopGesture => getxController.defaultPopGesture; | ||
| 1028 | + bool get defaultOpaqueRoute => getxController.defaultOpaqueRoute; | ||
| 1029 | + | ||
| 1030 | + Transition get defaultTransition => getxController.defaultTransition; | ||
| 1031 | + Duration get defaultTransitionDuration { | ||
| 1032 | + return getxController.defaultDialogTransitionDuration; | ||
| 1033 | + } | ||
| 1034 | + | ||
| 1035 | + Curve get defaultTransitionCurve => getxController.defaultTransitionCurve; | ||
| 1036 | + | ||
| 1037 | + Curve get defaultDialogTransitionCurve { | ||
| 1038 | + return getxController.defaultDialogTransitionCurve; | ||
| 1039 | + } | ||
| 1040 | + | ||
| 1041 | + Duration get defaultDialogTransitionDuration { | ||
| 1042 | + return getxController.defaultDialogTransitionDuration; | ||
| 1043 | + } | ||
| 1044 | + | ||
| 1045 | + Routing get routing => getxController.routing; | ||
| 1046 | + | ||
| 1047 | + Map<String, String> get parameters => getxController.parameters; | ||
| 1048 | + set parameters(Map<String, String> newParameters) => | ||
| 1049 | + getxController.parameters = newParameters; | ||
| 1050 | + | ||
| 1051 | + ParseRouteTree get routeTree => getxController.routeTree; | ||
| 1052 | + set routeTree(ParseRouteTree tree) => getxController.routeTree = tree; | ||
| 1053 | + | ||
| 1054 | + CustomTransition get customTransition => getxController.customTransition; | ||
| 1055 | + set customTransition(CustomTransition newTransition) => | ||
| 1056 | + getxController.customTransition = newTransition; | ||
| 1057 | + | ||
| 1058 | + static GetMaterialController getxController = GetMaterialController(); | ||
| 1037 | } | 1059 | } |
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | import '../../state_manager/simple/get_state.dart'; | 2 | import '../../state_manager/simple/get_state.dart'; |
| 3 | +import '../../utils/platform/platform.dart'; | ||
| 4 | +import '../routes/custom_transition.dart'; | ||
| 5 | +import '../routes/observers/route_observer.dart'; | ||
| 6 | +import '../routes/transitions_type.dart'; | ||
| 7 | +import 'parse_route.dart'; | ||
| 3 | 8 | ||
| 4 | class GetMaterialController extends GetxController { | 9 | class GetMaterialController extends GetxController { |
| 5 | - Key key; | 10 | + Key unikey; |
| 6 | ThemeData theme; | 11 | ThemeData theme; |
| 7 | ThemeMode themeMode; | 12 | ThemeMode themeMode; |
| 8 | 13 | ||
| 14 | + bool defaultPopGesture = GetPlatform.isIOS; | ||
| 15 | + bool defaultOpaqueRoute = true; | ||
| 16 | + | ||
| 17 | + Transition defaultTransition; | ||
| 18 | + Duration defaultTransitionDuration = Duration(milliseconds: 400); | ||
| 19 | + Curve defaultTransitionCurve = Curves.easeOutQuad; | ||
| 20 | + | ||
| 21 | + Curve defaultDialogTransitionCurve = Curves.easeOutQuad; | ||
| 22 | + Duration defaultDialogTransitionDuration = Duration(milliseconds: 400); | ||
| 23 | + | ||
| 24 | + final routing = Routing(); | ||
| 25 | + | ||
| 26 | + Map<String, String> parameters = {}; | ||
| 27 | + | ||
| 28 | + ParseRouteTree routeTree; | ||
| 29 | + | ||
| 30 | + CustomTransition customTransition; | ||
| 31 | + | ||
| 32 | + GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); | ||
| 33 | + | ||
| 34 | + Map<int, GlobalKey<NavigatorState>> keys = {}; | ||
| 35 | + | ||
| 9 | void setTheme(ThemeData value) { | 36 | void setTheme(ThemeData value) { |
| 10 | theme = value; | 37 | theme = value; |
| 11 | update(); | 38 | update(); |
| @@ -17,7 +44,7 @@ class GetMaterialController extends GetxController { | @@ -17,7 +44,7 @@ class GetMaterialController extends GetxController { | ||
| 17 | } | 44 | } |
| 18 | 45 | ||
| 19 | void restartApp() { | 46 | void restartApp() { |
| 20 | - key = UniqueKey(); | 47 | + unikey = UniqueKey(); |
| 21 | update(); | 48 | update(); |
| 22 | } | 49 | } |
| 23 | } | 50 | } |
| @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; | @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; | ||
| 3 | import '../../../get.dart'; | 3 | import '../../../get.dart'; |
| 4 | import '../../core/log.dart'; | 4 | import '../../core/log.dart'; |
| 5 | import '../../instance/get_instance.dart'; | 5 | import '../../instance/get_instance.dart'; |
| 6 | +import '../extension_navigation.dart'; | ||
| 6 | import '../routes/get_route.dart'; | 7 | import '../routes/get_route.dart'; |
| 7 | import 'root_controller.dart'; | 8 | import 'root_controller.dart'; |
| 8 | import 'smart_management.dart'; | 9 | import 'smart_management.dart'; |
| @@ -181,7 +182,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -181,7 +182,7 @@ class GetMaterialApp extends StatelessWidget { | ||
| 181 | @override | 182 | @override |
| 182 | Widget build(BuildContext context) { | 183 | Widget build(BuildContext context) { |
| 183 | return GetBuilder<GetMaterialController>( | 184 | return GetBuilder<GetMaterialController>( |
| 184 | - init: Get.getxController, | 185 | + init: Get.rootController, |
| 185 | dispose: (d) { | 186 | dispose: (d) { |
| 186 | onDispose?.call(); | 187 | onDispose?.call(); |
| 187 | }, | 188 | }, |
| @@ -191,9 +192,9 @@ class GetMaterialApp extends StatelessWidget { | @@ -191,9 +192,9 @@ class GetMaterialApp extends StatelessWidget { | ||
| 191 | if (fallbackLocale != null) Get.fallbackLocale = fallbackLocale; | 192 | if (fallbackLocale != null) Get.fallbackLocale = fallbackLocale; |
| 192 | 193 | ||
| 193 | if (translations != null) { | 194 | if (translations != null) { |
| 194 | - Get.translations = translations.keys; | 195 | + Get.addTranslations(translations.keys); |
| 195 | } else if (translationsKeys != null) { | 196 | } else if (translationsKeys != null) { |
| 196 | - Get.translations = translationsKeys; | 197 | + Get.addTranslations(translationsKeys); |
| 197 | } | 198 | } |
| 198 | 199 | ||
| 199 | Get.customTransition = customTransition; | 200 | Get.customTransition = customTransition; |
| @@ -211,12 +212,12 @@ class GetMaterialApp extends StatelessWidget { | @@ -211,12 +212,12 @@ class GetMaterialApp extends StatelessWidget { | ||
| 211 | defaultPopGesture: popGesture ?? Get.isPopGestureEnable, | 212 | defaultPopGesture: popGesture ?? Get.isPopGestureEnable, |
| 212 | defaultDurationTransition: | 213 | defaultDurationTransition: |
| 213 | transitionDuration ?? Get.defaultTransitionDuration, | 214 | transitionDuration ?? Get.defaultTransitionDuration, |
| 214 | - defaultGlobalState: defaultGlobalState ?? Get.defaultGlobalState, | 215 | + |
| 215 | ); | 216 | ); |
| 216 | }, | 217 | }, |
| 217 | builder: (_) { | 218 | builder: (_) { |
| 218 | return MaterialApp( | 219 | return MaterialApp( |
| 219 | - key: key, | 220 | + key: _.unikey, |
| 220 | navigatorKey: | 221 | navigatorKey: |
| 221 | (navigatorKey == null ? Get.key : Get.addKey(navigatorKey)), | 222 | (navigatorKey == null ? Get.key : Get.addKey(navigatorKey)), |
| 222 | home: home, | 223 | home: home, |
| 1 | +import 'dart:ui'; | ||
| 2 | +import '../../core/get_interface.dart'; | ||
| 1 | import '../../core/get_main.dart'; | 3 | import '../../core/get_main.dart'; |
| 2 | 4 | ||
| 3 | extension Trans on String { | 5 | extension Trans on String { |
| @@ -49,3 +51,43 @@ extension Trans on String { | @@ -49,3 +51,43 @@ extension Trans on String { | ||
| 49 | return key; | 51 | return key; |
| 50 | } | 52 | } |
| 51 | } | 53 | } |
| 54 | + | ||
| 55 | +class _IntlHost { | ||
| 56 | + Locale locale; | ||
| 57 | + | ||
| 58 | + Locale fallbackLocale; | ||
| 59 | + | ||
| 60 | + Map<String, Map<String, String>> translations = {}; | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +extension LocalesIntl on GetInterface { | ||
| 64 | + static final _intlHost = _IntlHost(); | ||
| 65 | + | ||
| 66 | + Locale get locale => _intlHost.locale; | ||
| 67 | + | ||
| 68 | + Locale get fallbackLocale => _intlHost.fallbackLocale; | ||
| 69 | + | ||
| 70 | + set locale(Locale newLocale) { | ||
| 71 | + _intlHost.locale = newLocale; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + set fallbackLocale(Locale newLocale) { | ||
| 75 | + _intlHost.fallbackLocale = newLocale; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + Map<String, Map<String, String>> get translations => _intlHost.translations; | ||
| 79 | + | ||
| 80 | + void addTranslations(Map<String, Map<String, String>> tr) { | ||
| 81 | + translations.addAll(tr); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + void appendTranslations(Map<String, Map<String, String>> tr) { | ||
| 85 | + tr.forEach((key, map) { | ||
| 86 | + if (translations.containsKey(key)) { | ||
| 87 | + translations[key].addAll(map); | ||
| 88 | + } else { | ||
| 89 | + translations[key] = map; | ||
| 90 | + } | ||
| 91 | + }); | ||
| 92 | + } | ||
| 93 | +} |
-
Please register or login to post a comment