Showing
14 changed files
with
841 additions
and
517 deletions
| @@ -20,3 +20,4 @@ export 'src/routes/bindings_interface.dart'; | @@ -20,3 +20,4 @@ export 'src/routes/bindings_interface.dart'; | ||
| 20 | export 'src/routes/observers/route_observer.dart'; | 20 | export 'src/routes/observers/route_observer.dart'; |
| 21 | export 'src/routes/transitions_type.dart'; | 21 | export 'src/routes/transitions_type.dart'; |
| 22 | export 'src/platform/platform.dart'; | 22 | export 'src/platform/platform.dart'; |
| 23 | +export 'src/extension_instance.dart'; |
lib/src/extension_instance.dart
0 → 100644
| 1 | +import 'get_instance.dart'; | ||
| 2 | +import 'get_main.dart'; | ||
| 3 | +import 'typedefs/typedefs.dart'; | ||
| 4 | + | ||
| 5 | +extension Storage on GetImpl { | ||
| 6 | + void lazyPut<S>(FcBuilderFunc builder, {String tag}) { | ||
| 7 | + return GetInstance().lazyPut<S>(builder, tag: tag); | ||
| 8 | + } | ||
| 9 | + | ||
| 10 | + Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder, {String tag}) async => | ||
| 11 | + GetInstance().putAsync<S>(builder, tag: tag); | ||
| 12 | + | ||
| 13 | + S find<S>({String tag, FcBuilderFunc<S> instance}) => | ||
| 14 | + GetInstance().find<S>(tag: tag, instance: instance); | ||
| 15 | + | ||
| 16 | + S put<S>(S dependency, | ||
| 17 | + {String tag, | ||
| 18 | + bool permanent = false, | ||
| 19 | + bool overrideAbstract = false, | ||
| 20 | + FcBuilderFunc<S> builder}) => | ||
| 21 | + GetInstance().put<S>(dependency, | ||
| 22 | + tag: tag, | ||
| 23 | + permanent: permanent, | ||
| 24 | + overrideAbstract: overrideAbstract, | ||
| 25 | + builder: builder); | ||
| 26 | + | ||
| 27 | + bool reset({bool clearFactory = true, bool clearRouteBindings = true}) => | ||
| 28 | + GetInstance().reset( | ||
| 29 | + clearFactory: clearFactory, clearRouteBindings: clearRouteBindings); | ||
| 30 | +} |
lib/src/get_instance.dart
0 → 100644
| 1 | +import 'root/smart_management.dart'; | ||
| 2 | +import 'rx/rx_interface.dart'; | ||
| 3 | +import 'typedefs/typedefs.dart'; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +class GetConfig { | ||
| 7 | + //////////// INSTANCE MANAGER | ||
| 8 | + static Map<dynamic, dynamic> _singl = {}; | ||
| 9 | + static Map<dynamic, FcBuilderFunc> _factory = {}; | ||
| 10 | + static Map<String, String> routesKey = {}; | ||
| 11 | + static SmartManagement smartManagement = SmartManagement.full; | ||
| 12 | + static bool isLogEnable = true; | ||
| 13 | + static String currentRoute; | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +class GetInstance { | ||
| 17 | + factory GetInstance() { | ||
| 18 | + if (_getInstance == null) _getInstance = GetInstance._(); | ||
| 19 | + return _getInstance; | ||
| 20 | + } | ||
| 21 | + GetInstance._(); | ||
| 22 | + static GetInstance _getInstance; | ||
| 23 | + | ||
| 24 | + void lazyPut<S>(FcBuilderFunc builder, {String tag}) { | ||
| 25 | + String key = _getKey(S, tag); | ||
| 26 | + GetConfig._factory.putIfAbsent(key, () => builder); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder, {String tag}) async { | ||
| 30 | + return put<S>(await builder(), tag: tag); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /// Inject class on Get Instance Manager | ||
| 34 | + S put<S>( | ||
| 35 | + S dependency, { | ||
| 36 | + String tag, | ||
| 37 | + bool permanent = false, | ||
| 38 | + bool overrideAbstract = false, | ||
| 39 | + FcBuilderFunc<S> builder, | ||
| 40 | + }) { | ||
| 41 | + _insert( | ||
| 42 | + isSingleton: true, | ||
| 43 | + replace: overrideAbstract, | ||
| 44 | + //?? (("$S" == "${dependency.runtimeType}") == false), | ||
| 45 | + name: tag, | ||
| 46 | + permanent: permanent, | ||
| 47 | + builder: builder ?? (() => dependency)); | ||
| 48 | + return find<S>(tag: tag); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + /// Create a new instance from builder class | ||
| 52 | + /// Example | ||
| 53 | + /// create(() => Repl()); | ||
| 54 | + /// Repl a = find(); | ||
| 55 | + /// Repl b = find(); | ||
| 56 | + /// print(a==b); (false) | ||
| 57 | + void create<S>( | ||
| 58 | + FcBuilderFunc<S> builder, { | ||
| 59 | + String name, | ||
| 60 | + }) { | ||
| 61 | + _insert(isSingleton: false, name: name, builder: builder); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + void _insert<S>({ | ||
| 65 | + bool isSingleton, | ||
| 66 | + String name, | ||
| 67 | + bool replace = true, | ||
| 68 | + bool permanent = false, | ||
| 69 | + FcBuilderFunc<S> builder, | ||
| 70 | + }) { | ||
| 71 | + assert(builder != null); | ||
| 72 | + String key = _getKey(S, name); | ||
| 73 | + if (replace) { | ||
| 74 | + GetConfig._singl[key] = FcBuilder<S>(isSingleton, builder, permanent); | ||
| 75 | + } else { | ||
| 76 | + GetConfig._singl.putIfAbsent( | ||
| 77 | + key, () => FcBuilder<S>(isSingleton, builder, permanent)); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + void removeDependencyByRoute(String routeName) async { | ||
| 82 | + List<String> keysToRemove = []; | ||
| 83 | + GetConfig.routesKey.forEach((key, value) { | ||
| 84 | + // if (value == routeName && value != null) { | ||
| 85 | + if (value == routeName) { | ||
| 86 | + keysToRemove.add(key); | ||
| 87 | + } | ||
| 88 | + }); | ||
| 89 | + keysToRemove.forEach((element) async { | ||
| 90 | + await delete(key: element); | ||
| 91 | + }); | ||
| 92 | + keysToRemove.forEach((element) { | ||
| 93 | + GetConfig.routesKey?.remove(element); | ||
| 94 | + }); | ||
| 95 | + keysToRemove.clear(); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + bool isRouteDependecyNull<S>({String name}) { | ||
| 99 | + return (GetConfig.routesKey[_getKey(S, name)] == null); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + bool isDependencyInit<S>({String name}) { | ||
| 103 | + String key = _getKey(S, name); | ||
| 104 | + return GetConfig.routesKey.containsKey(key); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + void registerRouteInstance<S>({String tag}) { | ||
| 108 | + // print("Register route [$S] as ${currentRoute}"); | ||
| 109 | + GetConfig.routesKey | ||
| 110 | + .putIfAbsent(_getKey(S, tag), () => GetConfig.currentRoute); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + S findByType<S>(Type type, {String tag}) { | ||
| 114 | + String key = _getKey(type, tag); | ||
| 115 | + return GetConfig._singl[key].getSependency(); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + void initController<S>({String tag}) { | ||
| 119 | + String key = _getKey(S, tag); | ||
| 120 | + final i = GetConfig._singl[key].getSependency(); | ||
| 121 | + | ||
| 122 | + if (i is DisposableInterface) { | ||
| 123 | + i.onStart(); | ||
| 124 | + if (GetConfig.isLogEnable) print('[GET] $key has been initialized'); | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /// Find a instance from required class | ||
| 129 | + S find<S>({String tag, FcBuilderFunc<S> instance}) { | ||
| 130 | + String key = _getKey(S, tag); | ||
| 131 | + bool callInit = false; | ||
| 132 | + if (isRegistred<S>(tag: tag)) { | ||
| 133 | + if (!isDependencyInit<S>() && | ||
| 134 | + GetConfig.smartManagement != SmartManagement.onlyBuilder) { | ||
| 135 | + registerRouteInstance<S>(tag: tag); | ||
| 136 | + callInit = true; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + FcBuilder builder = GetConfig._singl[key]; | ||
| 140 | + if (builder == null) { | ||
| 141 | + if (tag == null) { | ||
| 142 | + throw "class ${S.toString()} is not register"; | ||
| 143 | + } else { | ||
| 144 | + throw "class ${S.toString()} with tag '$tag' is not register"; | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + if (callInit) { | ||
| 148 | + initController<S>(tag: tag); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + return GetConfig._singl[key].getSependency(); | ||
| 152 | + } else { | ||
| 153 | + if (!GetConfig._factory.containsKey(key)) | ||
| 154 | + throw " $S not found. You need call put<$S>($S()) before"; | ||
| 155 | + | ||
| 156 | + if (GetConfig.isLogEnable) | ||
| 157 | + print('[GET] $S instance was created at that time'); | ||
| 158 | + S _value = put<S>(GetConfig._factory[key].call() as S); | ||
| 159 | + | ||
| 160 | + if (!isDependencyInit<S>() && | ||
| 161 | + GetConfig.smartManagement != SmartManagement.onlyBuilder) { | ||
| 162 | + registerRouteInstance<S>(tag: tag); | ||
| 163 | + callInit = true; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + if (GetConfig.smartManagement != SmartManagement.keepFactory) { | ||
| 167 | + GetConfig._factory.remove(key); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + if (callInit) { | ||
| 171 | + initController<S>(tag: tag); | ||
| 172 | + } | ||
| 173 | + return _value; | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + /// Remove dependency of [S] on dependency abstraction. For concrete class use delete | ||
| 178 | + void remove<S>({String tag}) { | ||
| 179 | + String key = _getKey(S, tag); | ||
| 180 | + FcBuilder builder = GetConfig._singl[key]; | ||
| 181 | + final i = builder.dependency; | ||
| 182 | + | ||
| 183 | + if (i is DisposableInterface) { | ||
| 184 | + i.onClose(); | ||
| 185 | + if (GetConfig.isLogEnable) print('[GET] onClose of $key called'); | ||
| 186 | + } | ||
| 187 | + if (builder != null) builder.dependency = null; | ||
| 188 | + if (GetConfig._singl.containsKey(key)) { | ||
| 189 | + print('error on remove $key'); | ||
| 190 | + } else { | ||
| 191 | + if (GetConfig.isLogEnable) print('[GET] $key removed from memory'); | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + String _getKey(Type type, String name) { | ||
| 196 | + return name == null ? type.toString() : type.toString() + name; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + bool reset({bool clearFactory = true, bool clearRouteBindings = true}) { | ||
| 200 | + if (clearFactory) GetConfig._factory.clear(); | ||
| 201 | + if (clearRouteBindings) GetConfig.routesKey.clear(); | ||
| 202 | + GetConfig._singl.clear(); | ||
| 203 | + return true; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + /// Delete class instance on [S] and clean memory | ||
| 207 | + Future<bool> delete<S>({String tag, String key}) async { | ||
| 208 | + String newKey; | ||
| 209 | + if (key == null) { | ||
| 210 | + newKey = _getKey(S, tag); | ||
| 211 | + } else { | ||
| 212 | + newKey = key; | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + if (!GetConfig._singl.containsKey(newKey)) { | ||
| 216 | + print('Instance $newKey not found'); | ||
| 217 | + return false; | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + FcBuilder builder = GetConfig._singl[newKey]; | ||
| 221 | + if (builder.permanent) { | ||
| 222 | + (key == null) | ||
| 223 | + ? print( | ||
| 224 | + '[GET] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.') | ||
| 225 | + : print( | ||
| 226 | + '[GET] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.'); | ||
| 227 | + return false; | ||
| 228 | + } | ||
| 229 | + final i = builder.dependency; | ||
| 230 | + | ||
| 231 | + if (i is DisposableInterface) { | ||
| 232 | + await i.onClose(); | ||
| 233 | + if (GetConfig.isLogEnable) print('[GET] onClose of $newKey called'); | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + GetConfig._singl.removeWhere((oldkey, value) => (oldkey == newKey)); | ||
| 237 | + if (GetConfig._singl.containsKey(newKey)) { | ||
| 238 | + print('[GET] error on remove object $newKey'); | ||
| 239 | + } else { | ||
| 240 | + if (GetConfig.isLogEnable) print('[GET] $newKey deleted from memory'); | ||
| 241 | + } | ||
| 242 | + // GetConfig.routesKey?.remove(key); | ||
| 243 | + return true; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /// check if instance is registred | ||
| 247 | + bool isRegistred<S>({String tag}) => | ||
| 248 | + GetConfig._singl.containsKey(_getKey(S, tag)); | ||
| 249 | + | ||
| 250 | + /// check if instance is prepared | ||
| 251 | + bool isPrepared<S>({String tag}) => | ||
| 252 | + GetConfig._factory.containsKey(_getKey(S, tag)); | ||
| 253 | +} |
lib/src/get_interface.dart
0 → 100644
| 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'; | ||
| 8 | + | ||
| 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" | ||
| 11 | +///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. | ||
| 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 | ||
| 14 | +///the parentheses and the magic will occur. | ||
| 15 | +/// | ||
| 16 | + | ||
| 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}); | ||
| 30 | + | ||
| 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}); | ||
| 35 | + | ||
| 36 | + /// It replaces Navigator.pushReplacementNamed, but needs no context. | ||
| 37 | + Future<T> offNamed<T>(String page, {Object arguments, int id}); | ||
| 38 | + | ||
| 39 | + /// It replaces Navigator.popUntil, but needs no context. | ||
| 40 | + void until(RoutePredicate predicate, {int id}); | ||
| 41 | + | ||
| 42 | + /// It replaces Navigator.pushAndRemoveUntil, but needs no context. | ||
| 43 | + Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}); | ||
| 44 | + | ||
| 45 | + /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | ||
| 46 | + Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, | ||
| 47 | + {int id, Object arguments}); | ||
| 48 | + | ||
| 49 | + /// It replaces Navigator.popAndPushNamed, but needs no context. | ||
| 50 | + Future<T> offAndToNamed<T>(String page, | ||
| 51 | + {Object arguments, int id, dynamic result}); | ||
| 52 | + | ||
| 53 | + /// It replaces Navigator.removeRoute, but needs no context. | ||
| 54 | + void removeRoute(Route<dynamic> route, {int id}); | ||
| 55 | + | ||
| 56 | + /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | ||
| 57 | + Future<T> offAllNamed<T>(String newRouteName, | ||
| 58 | + {RoutePredicate predicate, Object arguments, int id}); | ||
| 59 | + | ||
| 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 = false, | ||
| 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(title, 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 getController; | ||
| 228 | + | ||
| 229 | + changeTheme(ThemeData theme); | ||
| 230 | + | ||
| 231 | + 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; | ||
| 300 | +} |
| 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 | import 'package:get/get.dart'; | 3 | import 'package:get/get.dart'; |
| 4 | +import 'package:get/src/get_interface.dart'; | ||
| 4 | import 'bottomsheet/bottomsheet.dart'; | 5 | import 'bottomsheet/bottomsheet.dart'; |
| 5 | import 'platform/platform.dart'; | 6 | import 'platform/platform.dart'; |
| 6 | import 'root/root_controller.dart'; | 7 | import 'root/root_controller.dart'; |
| 7 | -import 'root/smart_management.dart'; | ||
| 8 | import 'routes/bindings_interface.dart'; | 8 | import 'routes/bindings_interface.dart'; |
| 9 | import 'routes/default_route.dart'; | 9 | import 'routes/default_route.dart'; |
| 10 | import 'routes/observers/route_observer.dart'; | 10 | import 'routes/observers/route_observer.dart'; |
| 11 | import 'routes/transitions_type.dart'; | 11 | import 'routes/transitions_type.dart'; |
| 12 | -import 'rx/rx_interface.dart'; | ||
| 13 | import 'snackbar/snack.dart'; | 12 | import 'snackbar/snack.dart'; |
| 14 | 13 | ||
| 15 | -///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | ||
| 16 | -///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 17 | -///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. | ||
| 18 | -///To return to the previous screen, use Get.back(). | 14 | +///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, |
| 15 | +///offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 16 | +///after them. Example: toNamed, offNamed, and AllNamed. | ||
| 17 | +///To return to the previous screen, use back(). | ||
| 19 | ///No need to pass any context to Get, just put the name of the route inside | 18 | ///No need to pass any context to Get, just put the name of the route inside |
| 20 | ///the parentheses and the magic will occur. | 19 | ///the parentheses and the magic will occur. |
| 21 | -class Get { | ||
| 22 | - factory Get() { | ||
| 23 | - if (_get == null) _get = Get._(); | ||
| 24 | - return _get; | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - bool _enableLog = true; | ||
| 28 | - bool _defaultPopGesture = GetPlatform.isIOS; | ||
| 29 | - bool _defaultOpaqueRoute = true; | ||
| 30 | - Transition _defaultTransition = | 20 | +class GetImpl implements GetService { |
| 21 | + bool defaultPopGesture = GetPlatform.isIOS; | ||
| 22 | + bool defaultOpaqueRoute = true; | ||
| 23 | + Transition defaultTransition = | ||
| 31 | (GetPlatform.isIOS ? Transition.cupertino : Transition.fade); | 24 | (GetPlatform.isIOS ? Transition.cupertino : Transition.fade); |
| 32 | - Duration _defaultDurationTransition = Duration(milliseconds: 400); | ||
| 33 | - bool _defaultGlobalState = true; | ||
| 34 | - RouteSettings _settings; | ||
| 35 | - SmartManagement smartManagement = SmartManagement.full; | ||
| 36 | - | ||
| 37 | - ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | ||
| 38 | - ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 39 | - ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. | ||
| 40 | - ///To return to the previous screen, use Get.back(). | 25 | + Duration defaultDurationTransition = Duration(milliseconds: 400); |
| 26 | + bool defaultGlobalState = true; | ||
| 27 | + RouteSettings settings; | ||
| 28 | + | ||
| 29 | + ///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, | ||
| 30 | + ///offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 31 | + ///after them. Example: toNamed, offNamed, and AllNamed. | ||
| 32 | + ///To return to the previous screen, use back(). | ||
| 41 | ///No need to pass any context to Get, just put the name of the route inside | 33 | ///No need to pass any context to Get, just put the name of the route inside |
| 42 | ///the parentheses and the magic will occur. | 34 | ///the parentheses and the magic will occur. |
| 43 | - Get._(); | ||
| 44 | - | ||
| 45 | - static Get _get; | ||
| 46 | - | ||
| 47 | - GlobalKey<NavigatorState> _key; | ||
| 48 | 35 | ||
| 49 | /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push | 36 | /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push |
| 50 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | 37 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior |
| 51 | /// of rebuilding every app after a route, use opaque = true as the parameter. | 38 | /// of rebuilding every app after a route, use opaque = true as the parameter. |
| 52 | - static Future<T> to<T>(Widget page, | 39 | + Future<T> to<T>(Widget page, |
| 53 | {bool opaque, | 40 | {bool opaque, |
| 54 | Transition transition, | 41 | Transition transition, |
| 55 | Duration duration, | 42 | Duration duration, |
| @@ -58,108 +45,104 @@ class Get { | @@ -58,108 +45,104 @@ class Get { | ||
| 58 | Object arguments, | 45 | Object arguments, |
| 59 | Bindings binding, | 46 | Bindings binding, |
| 60 | bool popGesture}) { | 47 | bool popGesture}) { |
| 61 | - return _get.global(id).currentState.push(GetRouteBase( | 48 | + return global(id).currentState.push(GetRouteBase( |
| 62 | opaque: opaque ?? true, | 49 | opaque: opaque ?? true, |
| 63 | page: page, | 50 | page: page, |
| 64 | settings: RouteSettings( | 51 | settings: RouteSettings( |
| 65 | name: '/' + page.toString().toLowerCase(), arguments: arguments), | 52 | name: '/' + page.toString().toLowerCase(), arguments: arguments), |
| 66 | - popGesture: popGesture ?? _get._defaultPopGesture, | ||
| 67 | - transition: transition ?? _get._defaultTransition, | 53 | + popGesture: popGesture ?? defaultPopGesture, |
| 54 | + transition: transition ?? defaultTransition, | ||
| 68 | fullscreenDialog: fullscreenDialog, | 55 | fullscreenDialog: fullscreenDialog, |
| 69 | binding: binding, | 56 | binding: binding, |
| 70 | - transitionDuration: duration ?? _get._defaultDurationTransition)); | 57 | + transitionDuration: duration ?? defaultDurationTransition)); |
| 71 | } | 58 | } |
| 72 | 59 | ||
| 73 | /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed | 60 | /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed |
| 74 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | 61 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior |
| 75 | /// of rebuilding every app after a route, use opaque = true as the parameter. | 62 | /// of rebuilding every app after a route, use opaque = true as the parameter. |
| 76 | - static Future<T> toNamed<T>(String page, {Object arguments, int id}) { | 63 | + Future<T> toNamed<T>(String page, {Object arguments, int id}) { |
| 77 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 64 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
| 78 | // when widget don't mounted | 65 | // when widget don't mounted |
| 79 | - return _get.global(id).currentState.pushNamed(page, arguments: arguments); | 66 | + return global(id).currentState.pushNamed(page, arguments: arguments); |
| 80 | } | 67 | } |
| 81 | 68 | ||
| 82 | /// It replaces Navigator.pushReplacementNamed, but needs no context. | 69 | /// It replaces Navigator.pushReplacementNamed, but needs no context. |
| 83 | - static Future<T> offNamed<T>(String page, {Object arguments, int id}) { | 70 | + Future<T> offNamed<T>(String page, {Object arguments, int id}) { |
| 84 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 71 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
| 85 | // when widget don't mounted | 72 | // when widget don't mounted |
| 86 | - return _get | ||
| 87 | - .global(id) | 73 | + return global(id) |
| 88 | .currentState | 74 | .currentState |
| 89 | .pushReplacementNamed(page, arguments: arguments); | 75 | .pushReplacementNamed(page, arguments: arguments); |
| 90 | } | 76 | } |
| 91 | 77 | ||
| 92 | /// It replaces Navigator.popUntil, but needs no context. | 78 | /// It replaces Navigator.popUntil, but needs no context. |
| 93 | - static void until(RoutePredicate predicate, {int id}) { | 79 | + void until(RoutePredicate predicate, {int id}) { |
| 94 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 80 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
| 95 | // when widget don't mounted | 81 | // when widget don't mounted |
| 96 | - return _get.global(id).currentState.popUntil(predicate); | 82 | + return global(id).currentState.popUntil(predicate); |
| 97 | } | 83 | } |
| 98 | 84 | ||
| 99 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context. | 85 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context. |
| 100 | - static Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, | ||
| 101 | - {int id}) { | 86 | + Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { |
| 102 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 87 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
| 103 | // when widget don't mounted | 88 | // when widget don't mounted |
| 104 | - return _get.global(id).currentState.pushAndRemoveUntil(page, predicate); | 89 | + return global(id).currentState.pushAndRemoveUntil(page, predicate); |
| 105 | } | 90 | } |
| 106 | 91 | ||
| 107 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 92 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. |
| 108 | - static Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, | 93 | + Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, |
| 109 | {int id, Object arguments}) { | 94 | {int id, Object arguments}) { |
| 110 | - return _get | ||
| 111 | - .global(id) | 95 | + return global(id) |
| 112 | .currentState | 96 | .currentState |
| 113 | .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); | 97 | .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); |
| 114 | } | 98 | } |
| 115 | 99 | ||
| 116 | /// It replaces Navigator.popAndPushNamed, but needs no context. | 100 | /// It replaces Navigator.popAndPushNamed, but needs no context. |
| 117 | - static Future<T> offAndToNamed<T>(String page, | 101 | + Future<T> offAndToNamed<T>(String page, |
| 118 | {Object arguments, int id, dynamic result}) { | 102 | {Object arguments, int id, dynamic result}) { |
| 119 | - return _get | ||
| 120 | - .global(id) | 103 | + return global(id) |
| 121 | .currentState | 104 | .currentState |
| 122 | .popAndPushNamed(page, arguments: arguments, result: result); | 105 | .popAndPushNamed(page, arguments: arguments, result: result); |
| 123 | } | 106 | } |
| 124 | 107 | ||
| 125 | /// It replaces Navigator.removeRoute, but needs no context. | 108 | /// It replaces Navigator.removeRoute, but needs no context. |
| 126 | - static void removeRoute(Route<dynamic> route, {int id}) { | ||
| 127 | - return _get.global(id).currentState.removeRoute(route); | 109 | + void removeRoute(Route<dynamic> route, {int id}) { |
| 110 | + return global(id).currentState.removeRoute(route); | ||
| 128 | } | 111 | } |
| 129 | 112 | ||
| 130 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 113 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. |
| 131 | - static Future<T> offAllNamed<T>(String newRouteName, | 114 | + Future<T> offAllNamed<T>(String newRouteName, |
| 132 | {RoutePredicate predicate, Object arguments, int id}) { | 115 | {RoutePredicate predicate, Object arguments, int id}) { |
| 133 | var route = (Route<dynamic> rota) => false; | 116 | var route = (Route<dynamic> rota) => false; |
| 134 | 117 | ||
| 135 | - return _get.global(id).currentState.pushNamedAndRemoveUntil( | 118 | + return global(id).currentState.pushNamedAndRemoveUntil( |
| 136 | newRouteName, predicate ?? route, | 119 | newRouteName, predicate ?? route, |
| 137 | arguments: arguments); | 120 | arguments: arguments); |
| 138 | } | 121 | } |
| 139 | 122 | ||
| 140 | - static bool get isOverlaysOpen => | 123 | + bool get isOverlaysOpen => |
| 141 | (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); | 124 | (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); |
| 142 | 125 | ||
| 143 | - static bool get isOverlaysClosed => | ||
| 144 | - (!Get.isSnackbarOpen && !Get.isDialogOpen && !Get.isBottomSheetOpen); | 126 | + bool get isOverlaysClosed => |
| 127 | + (!isSnackbarOpen && !isDialogOpen && !isBottomSheetOpen); | ||
| 145 | 128 | ||
| 146 | /// It replaces Navigator.pop, but needs no context. | 129 | /// It replaces Navigator.pop, but needs no context. |
| 147 | - static void back({dynamic result, bool closeOverlays = false, int id}) { | 130 | + void back({dynamic result, bool closeOverlays = false, int id}) { |
| 148 | if (closeOverlays && isOverlaysOpen) { | 131 | if (closeOverlays && isOverlaysOpen) { |
| 149 | navigator.popUntil((route) { | 132 | navigator.popUntil((route) { |
| 150 | return (isOverlaysClosed); | 133 | return (isOverlaysClosed); |
| 151 | }); | 134 | }); |
| 152 | } | 135 | } |
| 153 | - _get.global(id).currentState.pop(result); | 136 | + global(id).currentState.pop(result); |
| 154 | } | 137 | } |
| 155 | 138 | ||
| 156 | /// It will close as many screens as you define. Times must be> 0; | 139 | /// It will close as many screens as you define. Times must be> 0; |
| 157 | - static void close(int times, [int id]) { | 140 | + void close(int times, [int id]) { |
| 158 | if ((times == null) || (times < 1)) { | 141 | if ((times == null) || (times < 1)) { |
| 159 | times = 1; | 142 | times = 1; |
| 160 | } | 143 | } |
| 161 | int count = 0; | 144 | int count = 0; |
| 162 | - void back = _get.global(id).currentState.popUntil((route) { | 145 | + void back = global(id).currentState.popUntil((route) { |
| 163 | return count++ == times; | 146 | return count++ == times; |
| 164 | }); | 147 | }); |
| 165 | return back; | 148 | return back; |
| @@ -168,7 +151,7 @@ class Get { | @@ -168,7 +151,7 @@ class Get { | ||
| 168 | /// It replaces Navigator.pushReplacement, but needs no context, and it doesn't have the Navigator.pushReplacement | 151 | /// It replaces Navigator.pushReplacement, but needs no context, and it doesn't have the Navigator.pushReplacement |
| 169 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | 152 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior |
| 170 | /// of rebuilding every app after a route, use opaque = true as the parameter. | 153 | /// of rebuilding every app after a route, use opaque = true as the parameter. |
| 171 | - static Future<T> off<T>(Widget page, | 154 | + Future<T> off<T>(Widget page, |
| 172 | {bool opaque = false, | 155 | {bool opaque = false, |
| 173 | Transition transition, | 156 | Transition transition, |
| 174 | bool popGesture, | 157 | bool popGesture, |
| @@ -177,20 +160,20 @@ class Get { | @@ -177,20 +160,20 @@ class Get { | ||
| 177 | Bindings binding, | 160 | Bindings binding, |
| 178 | bool fullscreenDialog = false, | 161 | bool fullscreenDialog = false, |
| 179 | Duration duration}) { | 162 | Duration duration}) { |
| 180 | - return _get.global(id).currentState.pushReplacement(GetRouteBase( | 163 | + return global(id).currentState.pushReplacement(GetRouteBase( |
| 181 | opaque: opaque ?? true, | 164 | opaque: opaque ?? true, |
| 182 | page: page, | 165 | page: page, |
| 183 | binding: binding, | 166 | binding: binding, |
| 184 | settings: RouteSettings( | 167 | settings: RouteSettings( |
| 185 | name: '/' + page.toString().toLowerCase(), arguments: arguments), | 168 | name: '/' + page.toString().toLowerCase(), arguments: arguments), |
| 186 | fullscreenDialog: fullscreenDialog, | 169 | fullscreenDialog: fullscreenDialog, |
| 187 | - popGesture: popGesture ?? _get._defaultPopGesture, | ||
| 188 | - transition: transition ?? _get._defaultTransition, | ||
| 189 | - transitionDuration: duration ?? _get._defaultDurationTransition)); | 170 | + popGesture: popGesture ?? defaultPopGesture, |
| 171 | + transition: transition ?? defaultTransition, | ||
| 172 | + transitionDuration: duration ?? defaultDurationTransition)); | ||
| 190 | } | 173 | } |
| 191 | 174 | ||
| 192 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context | 175 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context |
| 193 | - static Future<T> offAll<T>(Widget page, | 176 | + Future<T> offAll<T>(Widget page, |
| 194 | {RoutePredicate predicate, | 177 | {RoutePredicate predicate, |
| 195 | bool opaque = false, | 178 | bool opaque = false, |
| 196 | bool popGesture, | 179 | bool popGesture, |
| @@ -201,22 +184,22 @@ class Get { | @@ -201,22 +184,22 @@ class Get { | ||
| 201 | Transition transition}) { | 184 | Transition transition}) { |
| 202 | var route = (Route<dynamic> rota) => false; | 185 | var route = (Route<dynamic> rota) => false; |
| 203 | 186 | ||
| 204 | - return _get.global(id).currentState.pushAndRemoveUntil( | 187 | + return global(id).currentState.pushAndRemoveUntil( |
| 205 | GetRouteBase( | 188 | GetRouteBase( |
| 206 | opaque: opaque ?? true, | 189 | opaque: opaque ?? true, |
| 207 | - popGesture: popGesture ?? _get._defaultPopGesture, | 190 | + popGesture: popGesture ?? defaultPopGesture, |
| 208 | page: page, | 191 | page: page, |
| 209 | binding: binding, | 192 | binding: binding, |
| 210 | settings: RouteSettings( | 193 | settings: RouteSettings( |
| 211 | name: '/' + page.toString().toLowerCase(), arguments: arguments), | 194 | name: '/' + page.toString().toLowerCase(), arguments: arguments), |
| 212 | fullscreenDialog: fullscreenDialog, | 195 | fullscreenDialog: fullscreenDialog, |
| 213 | - transition: transition ?? _get._defaultTransition, | 196 | + transition: transition ?? defaultTransition, |
| 214 | ), | 197 | ), |
| 215 | predicate ?? route); | 198 | predicate ?? route); |
| 216 | } | 199 | } |
| 217 | 200 | ||
| 218 | /// Show a dialog | 201 | /// Show a dialog |
| 219 | - static Future<T> dialog<T>( | 202 | + Future<T> dialog<T>( |
| 220 | Widget child, { | 203 | Widget child, { |
| 221 | bool barrierDismissible = true, | 204 | bool barrierDismissible = true, |
| 222 | bool useRootNavigator = true, | 205 | bool useRootNavigator = true, |
| @@ -234,7 +217,7 @@ class Get { | @@ -234,7 +217,7 @@ class Get { | ||
| 234 | } | 217 | } |
| 235 | 218 | ||
| 236 | /// Api from showGeneralDialog with no context | 219 | /// Api from showGeneralDialog with no context |
| 237 | - static Future<T> generalDialog<T>({ | 220 | + Future<T> generalDialog<T>({ |
| 238 | @required RoutePageBuilder pageBuilder, | 221 | @required RoutePageBuilder pageBuilder, |
| 239 | String barrierLabel = "Dismiss", | 222 | String barrierLabel = "Dismiss", |
| 240 | bool barrierDismissible = true, | 223 | bool barrierDismissible = true, |
| @@ -257,7 +240,7 @@ class Get { | @@ -257,7 +240,7 @@ class Get { | ||
| 257 | ); | 240 | ); |
| 258 | } | 241 | } |
| 259 | 242 | ||
| 260 | - static Future<T> defaultDialog<T>({ | 243 | + Future<T> defaultDialog<T>({ |
| 261 | String title = "Alert", | 244 | String title = "Alert", |
| 262 | Widget content, | 245 | Widget content, |
| 263 | VoidCallback onConfirm, | 246 | VoidCallback onConfirm, |
| @@ -289,7 +272,7 @@ class Get { | @@ -289,7 +272,7 @@ class Get { | ||
| 289 | materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | 272 | materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, |
| 290 | onPressed: () { | 273 | onPressed: () { |
| 291 | onCancel?.call(); | 274 | onCancel?.call(); |
| 292 | - Get.back(); | 275 | + back(); |
| 293 | }, | 276 | }, |
| 294 | padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8), | 277 | padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8), |
| 295 | child: Text( | 278 | child: Text( |
| @@ -298,7 +281,7 @@ class Get { | @@ -298,7 +281,7 @@ class Get { | ||
| 298 | ), | 281 | ), |
| 299 | shape: RoundedRectangleBorder( | 282 | shape: RoundedRectangleBorder( |
| 300 | side: BorderSide( | 283 | side: BorderSide( |
| 301 | - color: buttonColor ?? Get.theme.accentColor, | 284 | + color: buttonColor ?? theme.accentColor, |
| 302 | width: 2, | 285 | width: 2, |
| 303 | style: BorderStyle.solid), | 286 | style: BorderStyle.solid), |
| 304 | borderRadius: BorderRadius.circular(100)), | 287 | borderRadius: BorderRadius.circular(100)), |
| @@ -311,7 +294,7 @@ class Get { | @@ -311,7 +294,7 @@ class Get { | ||
| 311 | if (leanConfirm) { | 294 | if (leanConfirm) { |
| 312 | actions.add(FlatButton( | 295 | actions.add(FlatButton( |
| 313 | materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | 296 | materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, |
| 314 | - color: buttonColor ?? Get.theme.accentColor, | 297 | + color: buttonColor ?? theme.accentColor, |
| 315 | shape: RoundedRectangleBorder( | 298 | shape: RoundedRectangleBorder( |
| 316 | borderRadius: BorderRadius.circular(100)), | 299 | borderRadius: BorderRadius.circular(100)), |
| 317 | child: Text( | 300 | child: Text( |
| @@ -323,10 +306,10 @@ class Get { | @@ -323,10 +306,10 @@ class Get { | ||
| 323 | })); | 306 | })); |
| 324 | } | 307 | } |
| 325 | } | 308 | } |
| 326 | - return Get.dialog(AlertDialog( | 309 | + return dialog(AlertDialog( |
| 327 | titlePadding: EdgeInsets.all(8), | 310 | titlePadding: EdgeInsets.all(8), |
| 328 | contentPadding: EdgeInsets.all(8), | 311 | contentPadding: EdgeInsets.all(8), |
| 329 | - backgroundColor: backgroundColor ?? Get.theme.dialogBackgroundColor, | 312 | + backgroundColor: backgroundColor ?? theme.dialogBackgroundColor, |
| 330 | shape: RoundedRectangleBorder( | 313 | shape: RoundedRectangleBorder( |
| 331 | borderRadius: BorderRadius.all(Radius.circular(radius))), | 314 | borderRadius: BorderRadius.all(Radius.circular(radius))), |
| 332 | title: Text(title, textAlign: TextAlign.center), | 315 | title: Text(title, textAlign: TextAlign.center), |
| @@ -353,7 +336,7 @@ class Get { | @@ -353,7 +336,7 @@ class Get { | ||
| 353 | )); | 336 | )); |
| 354 | } | 337 | } |
| 355 | 338 | ||
| 356 | - static Future<T> bottomSheet<T>( | 339 | + Future<T> bottomSheet<T>( |
| 357 | Widget bottomsheet, { | 340 | Widget bottomsheet, { |
| 358 | Color backgroundColor, | 341 | Color backgroundColor, |
| 359 | double elevation, | 342 | double elevation, |
| @@ -375,10 +358,10 @@ class Get { | @@ -375,10 +358,10 @@ class Get { | ||
| 375 | return Navigator.of(overlayContext, rootNavigator: useRootNavigator) | 358 | return Navigator.of(overlayContext, rootNavigator: useRootNavigator) |
| 376 | .push(GetModalBottomSheetRoute<T>( | 359 | .push(GetModalBottomSheetRoute<T>( |
| 377 | builder: (_) => bottomsheet, | 360 | builder: (_) => bottomsheet, |
| 378 | - theme: Theme.of(Get.key.currentContext, shadowThemeOnly: true), | 361 | + theme: Theme.of(key.currentContext, shadowThemeOnly: true), |
| 379 | isScrollControlled: isScrollControlled, | 362 | isScrollControlled: isScrollControlled, |
| 380 | - barrierLabel: MaterialLocalizations.of(Get.key.currentContext) | ||
| 381 | - .modalBarrierDismissLabel, | 363 | + barrierLabel: |
| 364 | + MaterialLocalizations.of(key.currentContext).modalBarrierDismissLabel, | ||
| 382 | backgroundColor: backgroundColor ?? Colors.transparent, | 365 | backgroundColor: backgroundColor ?? Colors.transparent, |
| 383 | elevation: elevation, | 366 | elevation: elevation, |
| 384 | shape: shape, | 367 | shape: shape, |
| @@ -391,7 +374,7 @@ class Get { | @@ -391,7 +374,7 @@ class Get { | ||
| 391 | )); | 374 | )); |
| 392 | } | 375 | } |
| 393 | 376 | ||
| 394 | - static void rawSnackbar( | 377 | + void rawSnackbar( |
| 395 | {String title, | 378 | {String title, |
| 396 | String message, | 379 | String message, |
| 397 | Widget titleText, | 380 | Widget titleText, |
| @@ -473,12 +456,12 @@ class Get { | @@ -473,12 +456,12 @@ class Get { | ||
| 473 | } | 456 | } |
| 474 | } | 457 | } |
| 475 | 458 | ||
| 476 | - static void snackbar(title, message, | 459 | + void snackbar(title, message, |
| 477 | {Color colorText, | 460 | {Color colorText, |
| 478 | Duration duration, | 461 | Duration duration, |
| 479 | 462 | ||
| 480 | - /// with instantInit = false you can put Get.snackbar on initState | ||
| 481 | - bool instantInit = false, | 463 | + /// with instantInit = false you can put snackbar on initState |
| 464 | + bool instantInit = true, | ||
| 482 | SnackPosition snackPosition, | 465 | SnackPosition snackPosition, |
| 483 | Widget titleText, | 466 | Widget titleText, |
| 484 | Widget messageText, | 467 | Widget messageText, |
| @@ -563,7 +546,7 @@ class Get { | @@ -563,7 +546,7 @@ class Get { | ||
| 563 | if (instantInit) { | 546 | if (instantInit) { |
| 564 | getBar.show(); | 547 | getBar.show(); |
| 565 | } else { | 548 | } else { |
| 566 | - Get()._routing.isSnackbar = true; | 549 | + _routing.isSnackbar = true; |
| 567 | SchedulerBinding.instance.addPostFrameCallback((_) { | 550 | SchedulerBinding.instance.addPostFrameCallback((_) { |
| 568 | getBar.show(); | 551 | getBar.show(); |
| 569 | }); | 552 | }); |
| @@ -571,7 +554,7 @@ class Get { | @@ -571,7 +554,7 @@ class Get { | ||
| 571 | } | 554 | } |
| 572 | 555 | ||
| 573 | /// change default config of Get | 556 | /// change default config of Get |
| 574 | - Get.config( | 557 | + config( |
| 575 | {bool enableLog, | 558 | {bool enableLog, |
| 576 | bool defaultPopGesture, | 559 | bool defaultPopGesture, |
| 577 | bool defaultOpaqueRoute, | 560 | bool defaultOpaqueRoute, |
| @@ -579,57 +562,49 @@ class Get { | @@ -579,57 +562,49 @@ class Get { | ||
| 579 | bool defaultGlobalState, | 562 | bool defaultGlobalState, |
| 580 | Transition defaultTransition}) { | 563 | Transition defaultTransition}) { |
| 581 | if (enableLog != null) { | 564 | if (enableLog != null) { |
| 582 | - Get()._enableLog = enableLog; | 565 | + enableLog = enableLog; |
| 583 | } | 566 | } |
| 584 | if (defaultPopGesture != null) { | 567 | if (defaultPopGesture != null) { |
| 585 | - Get()._defaultPopGesture = defaultPopGesture; | 568 | + defaultPopGesture = defaultPopGesture; |
| 586 | } | 569 | } |
| 587 | if (defaultOpaqueRoute != null) { | 570 | if (defaultOpaqueRoute != null) { |
| 588 | - Get()._defaultOpaqueRoute = defaultOpaqueRoute; | 571 | + defaultOpaqueRoute = defaultOpaqueRoute; |
| 589 | } | 572 | } |
| 590 | if (defaultTransition != null) { | 573 | if (defaultTransition != null) { |
| 591 | - Get()._defaultTransition = defaultTransition; | 574 | + defaultTransition = defaultTransition; |
| 592 | } | 575 | } |
| 593 | 576 | ||
| 594 | if (defaultDurationTransition != null) { | 577 | if (defaultDurationTransition != null) { |
| 595 | - Get()._defaultDurationTransition = defaultDurationTransition; | 578 | + defaultDurationTransition = defaultDurationTransition; |
| 596 | } | 579 | } |
| 597 | 580 | ||
| 598 | if (defaultGlobalState != null) { | 581 | if (defaultGlobalState != null) { |
| 599 | - Get()._defaultGlobalState = defaultGlobalState; | 582 | + defaultGlobalState = defaultGlobalState; |
| 600 | } | 583 | } |
| 601 | } | 584 | } |
| 602 | 585 | ||
| 603 | - GetMaterialController _getController = GetMaterialController(); | ||
| 604 | - | ||
| 605 | - GetMaterialController get getController => _getController; | 586 | + GetMaterialController getController = GetMaterialController(); |
| 606 | 587 | ||
| 607 | - Get.changeTheme(ThemeData theme) { | ||
| 608 | - Get()._getController.setTheme(theme); | 588 | + changeTheme(ThemeData theme) { |
| 589 | + getController.setTheme(theme); | ||
| 609 | } | 590 | } |
| 610 | 591 | ||
| 611 | - Get.changeThemeMode(ThemeMode themeMode) { | ||
| 612 | - Get()._getController.setThemeMode(themeMode); | 592 | + changeThemeMode(ThemeMode themeMode) { |
| 593 | + getController.setThemeMode(themeMode); | ||
| 613 | } | 594 | } |
| 614 | 595 | ||
| 615 | - static GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { | ||
| 616 | - Get()._key = newKey; | ||
| 617 | - return Get()._key; | 596 | + GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { |
| 597 | + key = newKey; | ||
| 598 | + return key; | ||
| 618 | } | 599 | } |
| 619 | 600 | ||
| 620 | - static GlobalKey<NavigatorState> get key { | ||
| 621 | - // _get start empty, is mandatory key be static to prevent errors like "key was called null" | ||
| 622 | - if (Get()._key == null) { | ||
| 623 | - Get()._key = GlobalKey<NavigatorState>(); | ||
| 624 | - } | ||
| 625 | - return Get()._key; | ||
| 626 | - } | 601 | + GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); |
| 627 | 602 | ||
| 628 | Map<int, GlobalKey<NavigatorState>> _keys = {}; | 603 | Map<int, GlobalKey<NavigatorState>> _keys = {}; |
| 629 | - UniqueKey mKey = UniqueKey(); | ||
| 630 | - static GlobalKey<NavigatorState> nestedKey(int key) { | ||
| 631 | - Get()._keys.putIfAbsent(key, () => GlobalKey<NavigatorState>()); | ||
| 632 | - return Get()._keys[key]; | 604 | + |
| 605 | + GlobalKey<NavigatorState> nestedKey(int key) { | ||
| 606 | + _keys.putIfAbsent(key, () => GlobalKey<NavigatorState>()); | ||
| 607 | + return _keys[key]; | ||
| 633 | } | 608 | } |
| 634 | 609 | ||
| 635 | GlobalKey<NavigatorState> global(int k) { | 610 | GlobalKey<NavigatorState> global(int k) { |
| @@ -642,366 +617,94 @@ class Get { | @@ -642,366 +617,94 @@ class Get { | ||
| 642 | return _keys[k]; | 617 | return _keys[k]; |
| 643 | } | 618 | } |
| 644 | 619 | ||
| 645 | - //////////// INSTANCE MANAGER | ||
| 646 | - Map<dynamic, dynamic> _singl = {}; | ||
| 647 | - | ||
| 648 | - Map<dynamic, _FcBuilderFunc> _factory = {}; | ||
| 649 | - | ||
| 650 | - static void lazyPut<S>(_FcBuilderFunc builder, {String tag}) { | ||
| 651 | - String key = _getKey(S, tag); | ||
| 652 | - Get()._factory.putIfAbsent(key, () => builder); | ||
| 653 | - } | ||
| 654 | - | ||
| 655 | - static Future<S> putAsync<S>(_FcBuilderFuncAsync<S> builder, | ||
| 656 | - {String tag}) async { | ||
| 657 | - WidgetsFlutterBinding.ensureInitialized(); | ||
| 658 | - return Get.put<S>(await builder(), tag: tag); | ||
| 659 | - } | ||
| 660 | - | ||
| 661 | - /// Inject class on Get Instance Manager | ||
| 662 | - static S put<S>( | ||
| 663 | - S dependency, { | ||
| 664 | - String tag, | ||
| 665 | - bool permanent = false, | ||
| 666 | - bool overrideAbstract = false, | ||
| 667 | - _FcBuilderFunc<S> builder, | ||
| 668 | - }) { | ||
| 669 | - _insert( | ||
| 670 | - isSingleton: true, | ||
| 671 | - replace: overrideAbstract, | ||
| 672 | - //?? (("$S" == "${dependency.runtimeType}") == false), | ||
| 673 | - name: tag, | ||
| 674 | - permanent: permanent, | ||
| 675 | - builder: builder ?? (() => dependency)); | ||
| 676 | - return find<S>(tag: tag); | ||
| 677 | - } | ||
| 678 | - | ||
| 679 | - /// Create a new instance from builder class | ||
| 680 | - /// Example | ||
| 681 | - /// Get.create(() => Repl()); | ||
| 682 | - /// Repl a = Get.find(); | ||
| 683 | - /// Repl b = Get.find(); | ||
| 684 | - /// print(a==b); (false) | ||
| 685 | - static void create<S>( | ||
| 686 | - _FcBuilderFunc<S> builder, { | ||
| 687 | - String name, | ||
| 688 | - }) { | ||
| 689 | - _insert(isSingleton: false, name: name, builder: builder); | ||
| 690 | - } | ||
| 691 | - | ||
| 692 | - static void _insert<S>({ | ||
| 693 | - bool isSingleton, | ||
| 694 | - String name, | ||
| 695 | - bool replace = true, | ||
| 696 | - bool permanent = false, | ||
| 697 | - _FcBuilderFunc<S> builder, | ||
| 698 | - }) { | ||
| 699 | - assert(builder != null); | ||
| 700 | - String key = _getKey(S, name); | ||
| 701 | - if (replace) { | ||
| 702 | - Get()._singl[key] = _FcBuilder<S>(isSingleton, builder, permanent); | ||
| 703 | - } else { | ||
| 704 | - Get()._singl.putIfAbsent( | ||
| 705 | - key, () => _FcBuilder<S>(isSingleton, builder, permanent)); | ||
| 706 | - } | ||
| 707 | - } | ||
| 708 | - | ||
| 709 | - Map<String, String> routesKey = {}; | ||
| 710 | - | ||
| 711 | - void removeDependencyByRoute(String routeName) async { | ||
| 712 | - List<String> keysToRemove = []; | ||
| 713 | - Get().routesKey.forEach((key, value) { | ||
| 714 | - // if (value == routeName && value != null) { | ||
| 715 | - if (value == routeName) { | ||
| 716 | - keysToRemove.add(key); | ||
| 717 | - } | ||
| 718 | - }); | ||
| 719 | - keysToRemove.forEach((element) async { | ||
| 720 | - await Get.delete(key: element); | ||
| 721 | - }); | ||
| 722 | - keysToRemove.forEach((element) { | ||
| 723 | - Get().routesKey?.remove(element); | ||
| 724 | - }); | ||
| 725 | - keysToRemove.clear(); | ||
| 726 | - } | ||
| 727 | - | ||
| 728 | - static bool isRouteDependecyNull<S>({String name}) { | ||
| 729 | - return (Get().routesKey[_getKey(S, name)] == null); | ||
| 730 | - } | ||
| 731 | - | ||
| 732 | - static bool isDependencyInit<S>({String name}) { | ||
| 733 | - String key = _getKey(S, name); | ||
| 734 | - return Get().routesKey.containsKey(key); | ||
| 735 | - } | ||
| 736 | - | ||
| 737 | - void registerRouteInstance<S>({String tag}) { | ||
| 738 | - // print("Register route [$S] as ${Get.currentRoute}"); | ||
| 739 | - Get().routesKey.putIfAbsent(_getKey(S, tag), () => Get.currentRoute); | ||
| 740 | - } | ||
| 741 | - | ||
| 742 | - static S findByType<S>(Type type, {String tag}) { | ||
| 743 | - String key = _getKey(type, tag); | ||
| 744 | - return Get()._singl[key].getSependency(); | ||
| 745 | - } | ||
| 746 | - | ||
| 747 | - void initController<S>({String tag}) { | ||
| 748 | - String key = _getKey(S, tag); | ||
| 749 | - final i = Get()._singl[key].getSependency(); | ||
| 750 | - | ||
| 751 | - if (i is DisposableInterface) { | ||
| 752 | - i.onStart(); | ||
| 753 | - if (isLogEnable) print('[GET] $key has been initialized'); | ||
| 754 | - } | ||
| 755 | - } | ||
| 756 | - | ||
| 757 | - /// Find a instance from required class | ||
| 758 | - static S find<S>({String tag, _FcBuilderFunc<S> instance}) { | ||
| 759 | - String key = _getKey(S, tag); | ||
| 760 | - bool callInit = false; | ||
| 761 | - if (Get.isRegistred<S>(tag: tag)) { | ||
| 762 | - if (!isDependencyInit<S>() && | ||
| 763 | - Get().smartManagement != SmartManagement.onlyBuilder) { | ||
| 764 | - Get().registerRouteInstance<S>(tag: tag); | ||
| 765 | - callInit = true; | ||
| 766 | - } | ||
| 767 | - | ||
| 768 | - _FcBuilder builder = Get()._singl[key]; | ||
| 769 | - if (builder == null) { | ||
| 770 | - if (tag == null) { | ||
| 771 | - throw "class ${S.toString()} is not register"; | ||
| 772 | - } else { | ||
| 773 | - throw "class ${S.toString()} with tag '$tag' is not register"; | ||
| 774 | - } | ||
| 775 | - } | ||
| 776 | - if (callInit) { | ||
| 777 | - Get().initController<S>(tag: tag); | ||
| 778 | - } | ||
| 779 | - | ||
| 780 | - return Get()._singl[key].getSependency(); | ||
| 781 | - } else { | ||
| 782 | - if (!Get()._factory.containsKey(key)) | ||
| 783 | - throw " $S not found. You need call Get.put<$S>($S()) before"; | ||
| 784 | - | ||
| 785 | - if (isLogEnable) print('[GET] $S instance was created at that time'); | ||
| 786 | - S _value = Get.put<S>(Get()._factory[key].call() as S); | ||
| 787 | - | ||
| 788 | - if (!isDependencyInit<S>() && | ||
| 789 | - Get().smartManagement != SmartManagement.onlyBuilder) { | ||
| 790 | - Get().registerRouteInstance<S>(tag: tag); | ||
| 791 | - callInit = true; | ||
| 792 | - } | ||
| 793 | - | ||
| 794 | - if (Get().smartManagement != SmartManagement.keepFactory) { | ||
| 795 | - Get()._factory.remove(key); | ||
| 796 | - } | ||
| 797 | - | ||
| 798 | - if (callInit) { | ||
| 799 | - Get().initController<S>(tag: tag); | ||
| 800 | - } | ||
| 801 | - return _value; | ||
| 802 | - } | ||
| 803 | - } | ||
| 804 | - | ||
| 805 | - /// Remove dependency of [S] on dependency abstraction. For concrete class use Get.delete | ||
| 806 | - static void remove<S>({String tag}) { | ||
| 807 | - String key = _getKey(S, tag); | ||
| 808 | - _FcBuilder builder = Get()._singl[key]; | ||
| 809 | - final i = builder.dependency; | ||
| 810 | - | ||
| 811 | - if (i is DisposableInterface || i is GetController) { | ||
| 812 | - i.onClose(); | ||
| 813 | - if (isLogEnable) print('[GET] onClose of $key called'); | ||
| 814 | - } | ||
| 815 | - if (builder != null) builder.dependency = null; | ||
| 816 | - if (Get()._singl.containsKey(key)) { | ||
| 817 | - print('error on remove $key'); | ||
| 818 | - } else { | ||
| 819 | - if (isLogEnable) print('[GET] $key removed from memory'); | ||
| 820 | - } | ||
| 821 | - } | ||
| 822 | - | ||
| 823 | - static String _getKey(Type type, String name) { | ||
| 824 | - return name == null ? type.toString() : type.toString() + name; | ||
| 825 | - } | ||
| 826 | - | ||
| 827 | - static bool reset( | ||
| 828 | - {bool clearFactory = true, bool clearRouteBindings = true}) { | ||
| 829 | - if (clearFactory) Get()._factory.clear(); | ||
| 830 | - if (clearRouteBindings) Get().routesKey.clear(); | ||
| 831 | - Get()._singl.clear(); | ||
| 832 | - return true; | ||
| 833 | - } | ||
| 834 | - | ||
| 835 | - /// Delete class instance on [S] and clean memory | ||
| 836 | - static Future<bool> delete<S>({String tag, String key}) async { | ||
| 837 | - String newKey; | ||
| 838 | - if (key == null) { | ||
| 839 | - newKey = _getKey(S, tag); | ||
| 840 | - } else { | ||
| 841 | - newKey = key; | ||
| 842 | - } | ||
| 843 | - | ||
| 844 | - if (!Get()._singl.containsKey(newKey)) { | ||
| 845 | - print('Instance $newKey not found'); | ||
| 846 | - return false; | ||
| 847 | - } | ||
| 848 | - | ||
| 849 | - _FcBuilder builder = Get()._singl[newKey]; | ||
| 850 | - if (builder.permanent) { | ||
| 851 | - (key == null) | ||
| 852 | - ? print( | ||
| 853 | - '[GET] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.') | ||
| 854 | - : print( | ||
| 855 | - '[GET] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.'); | ||
| 856 | - return false; | ||
| 857 | - } | ||
| 858 | - final i = builder.dependency; | ||
| 859 | - | ||
| 860 | - if (i is DisposableInterface || i is GetController) { | ||
| 861 | - await i.onClose(); | ||
| 862 | - if (isLogEnable) print('[GET] onClose of $newKey called'); | ||
| 863 | - } | ||
| 864 | - | ||
| 865 | - Get()._singl.removeWhere((oldkey, value) => (oldkey == newKey)); | ||
| 866 | - if (Get()._singl.containsKey(newKey)) { | ||
| 867 | - print('[GET] error on remove object $newKey'); | ||
| 868 | - } else { | ||
| 869 | - if (isLogEnable) print('[GET] $newKey deleted from memory'); | ||
| 870 | - } | ||
| 871 | - // Get().routesKey?.remove(key); | ||
| 872 | - return true; | ||
| 873 | - } | ||
| 874 | - | ||
| 875 | - /// check if instance is registred | ||
| 876 | - static bool isRegistred<S>({String tag}) => | ||
| 877 | - Get()._singl.containsKey(_getKey(S, tag)); | ||
| 878 | - | ||
| 879 | - static bool isPrepared<S>({String tag}) => | ||
| 880 | - Get()._factory.containsKey(_getKey(S, tag)); | ||
| 881 | - | ||
| 882 | /// give access to Routing API from GetObserver | 620 | /// give access to Routing API from GetObserver |
| 883 | - static Routing get routing => Get()._routing; | 621 | + Routing get routing => _routing; |
| 884 | 622 | ||
| 885 | - static RouteSettings get routeSettings => Get()._settings; | 623 | + RouteSettings get routeSettings => settings; |
| 886 | 624 | ||
| 887 | Routing _routing = Routing(); | 625 | Routing _routing = Routing(); |
| 888 | 626 | ||
| 889 | Map<String, String> _parameters = {}; | 627 | Map<String, String> _parameters = {}; |
| 890 | 628 | ||
| 891 | - Get.setParameter(Map<String, String> param) { | ||
| 892 | - Get()._parameters = param; | 629 | + setParameter(Map<String, String> param) { |
| 630 | + _parameters = param; | ||
| 893 | } | 631 | } |
| 894 | 632 | ||
| 895 | - Get.setRouting(Routing rt) { | ||
| 896 | - Get()._routing = rt; | 633 | + setRouting(Routing rt) { |
| 634 | + _routing = rt; | ||
| 897 | } | 635 | } |
| 898 | 636 | ||
| 899 | - Get.setSettings(RouteSettings settings) { | ||
| 900 | - Get()._settings = settings; | 637 | + setSettings(RouteSettings settings) { |
| 638 | + settings = settings; | ||
| 901 | } | 639 | } |
| 902 | 640 | ||
| 903 | /// give current arguments | 641 | /// give current arguments |
| 904 | - static Object get arguments => Get()._routing.args; | 642 | + Object get arguments => _routing.args; |
| 905 | 643 | ||
| 906 | /// give current arguments | 644 | /// give current arguments |
| 907 | - static Map<String, String> get parameters => Get()._parameters; | 645 | + Map<String, String> get parameters => _parameters; |
| 908 | 646 | ||
| 909 | /// give name from current route | 647 | /// give name from current route |
| 910 | - static get currentRoute => Get()._routing.current; | 648 | + get currentRoute => _routing.current; |
| 911 | 649 | ||
| 912 | /// give name from previous route | 650 | /// give name from previous route |
| 913 | - static get previousRoute => Get()._routing.previous; | 651 | + get previousRoute => _routing.previous; |
| 914 | 652 | ||
| 915 | /// check if snackbar is open | 653 | /// check if snackbar is open |
| 916 | - static bool get isSnackbarOpen => Get()._routing.isSnackbar; | 654 | + bool get isSnackbarOpen => _routing.isSnackbar; |
| 917 | 655 | ||
| 918 | /// check if dialog is open | 656 | /// check if dialog is open |
| 919 | - static bool get isDialogOpen => Get()._routing.isDialog; | 657 | + bool get isDialogOpen => _routing.isDialog; |
| 920 | 658 | ||
| 921 | /// check if bottomsheet is open | 659 | /// check if bottomsheet is open |
| 922 | - static bool get isBottomSheetOpen => Get()._routing.isBottomSheet; | 660 | + bool get isBottomSheetOpen => _routing.isBottomSheet; |
| 923 | 661 | ||
| 924 | /// check a raw current route | 662 | /// check a raw current route |
| 925 | - static Route<dynamic> get rawRoute => Get()._routing.route; | ||
| 926 | - | ||
| 927 | - /// check if log is enable | ||
| 928 | - static bool get isLogEnable => Get()._enableLog; | ||
| 929 | - | ||
| 930 | - /// default duration of transition animation | ||
| 931 | - /// default duration work only API 2.0 | ||
| 932 | - static Duration get defaultDurationTransition => | ||
| 933 | - Get()._defaultDurationTransition; | ||
| 934 | - | ||
| 935 | - /// give global state of all GetState by default | ||
| 936 | - static bool get defaultGlobalState => Get()._defaultGlobalState; | 663 | + Route<dynamic> get rawRoute => _routing.route; |
| 937 | 664 | ||
| 938 | /// check if popGesture is enable | 665 | /// check if popGesture is enable |
| 939 | - static bool get isPopGestureEnable => Get()._defaultPopGesture; | 666 | + bool get isPopGestureEnable => defaultPopGesture; |
| 940 | 667 | ||
| 941 | /// check if default opaque route is enable | 668 | /// check if default opaque route is enable |
| 942 | - static bool get isOpaqueRouteDefault => Get()._defaultOpaqueRoute; | ||
| 943 | - | ||
| 944 | - static Transition get defaultTransition => Get()._defaultTransition; | 669 | + bool get isOpaqueRouteDefault => defaultOpaqueRoute; |
| 945 | 670 | ||
| 946 | /// give access to currentContext | 671 | /// give access to currentContext |
| 947 | - static BuildContext get context => key.currentContext; | 672 | + BuildContext get context => key.currentContext; |
| 948 | 673 | ||
| 949 | /// give access to current Overlay Context | 674 | /// give access to current Overlay Context |
| 950 | - static BuildContext get overlayContext => key.currentState.overlay.context; | 675 | + BuildContext get overlayContext => key.currentState.overlay.context; |
| 951 | 676 | ||
| 952 | /// give access to Theme.of(context) | 677 | /// give access to Theme.of(context) |
| 953 | - static ThemeData get theme => Theme.of(context); | 678 | + ThemeData get theme => Theme.of(context); |
| 954 | 679 | ||
| 955 | /// give access to TextTheme.of(context) | 680 | /// give access to TextTheme.of(context) |
| 956 | - static TextTheme get textTheme => Theme.of(context).textTheme; | 681 | + TextTheme get textTheme => Theme.of(context).textTheme; |
| 957 | 682 | ||
| 958 | /// give access to Mediaquery.of(context) | 683 | /// give access to Mediaquery.of(context) |
| 959 | - static MediaQueryData get mediaQuery => MediaQuery.of(context); | 684 | + MediaQueryData get mediaQuery => MediaQuery.of(context); |
| 960 | 685 | ||
| 961 | /// Check if dark mode theme is enable | 686 | /// Check if dark mode theme is enable |
| 962 | - static get isDarkMode => (theme.brightness == Brightness.dark); | 687 | + get isDarkMode => (theme.brightness == Brightness.dark); |
| 963 | 688 | ||
| 964 | /// Check if dark mode theme is enable on platform on android Q+ | 689 | /// Check if dark mode theme is enable on platform on android Q+ |
| 965 | - static get isPlatformDarkMode => | ||
| 966 | - (mediaQuery.platformBrightness == Brightness.dark); | 690 | + get isPlatformDarkMode => (mediaQuery.platformBrightness == Brightness.dark); |
| 967 | 691 | ||
| 968 | /// give access to Theme.of(context).iconTheme.color | 692 | /// give access to Theme.of(context).iconTheme.color |
| 969 | - static Color get iconColor => Theme.of(context).iconTheme.color; | 693 | + Color get iconColor => Theme.of(context).iconTheme.color; |
| 970 | 694 | ||
| 971 | - /// give access to Focus.of(context).iconTheme.color | ||
| 972 | - static FocusScopeNode get focusScope => FocusScope.of(context); | 695 | + /// give access to FocusScope.of(context) |
| 696 | + FocusNode get focusScope => FocusManager.instance.primaryFocus; | ||
| 973 | 697 | ||
| 974 | - /// give access to MediaQuery.of(context).size.height | ||
| 975 | - static double get height => MediaQuery.of(context).size.height; | 698 | + /// give access to Immutable MediaQuery.of(context).size.height |
| 699 | + double get height => MediaQuery.of(context).size.height; | ||
| 976 | 700 | ||
| 977 | - /// give access to MediaQuery.of(context).size.width | ||
| 978 | - static double get width => MediaQuery.of(context).size.width; | 701 | + /// give access to Immutable MediaQuery.of(context).size.width |
| 702 | + double get width => MediaQuery.of(context).size.width; | ||
| 979 | } | 703 | } |
| 980 | 704 | ||
| 705 | +// ignore: non_constant_identifier_names | ||
| 706 | +final Get = GetImpl(); | ||
| 707 | + | ||
| 981 | /// It replaces the Flutter Navigator, but needs no context. | 708 | /// It replaces the Flutter Navigator, but needs no context. |
| 982 | /// You can to use navigator.push(YourRoute()) rather Navigator.push(context, YourRoute()); | 709 | /// You can to use navigator.push(YourRoute()) rather Navigator.push(context, YourRoute()); |
| 983 | NavigatorState get navigator => Get.key.currentState; | 710 | NavigatorState get navigator => Get.key.currentState; |
| 984 | - | ||
| 985 | -class _FcBuilder<S> { | ||
| 986 | - bool isSingleton; | ||
| 987 | - _FcBuilderFunc builderFunc; | ||
| 988 | - S dependency; | ||
| 989 | - bool permanent = false; | ||
| 990 | - | ||
| 991 | - _FcBuilder(this.isSingleton, this.builderFunc, this.permanent); | ||
| 992 | - | ||
| 993 | - S getSependency() { | ||
| 994 | - if (isSingleton) { | ||
| 995 | - if (dependency == null) { | ||
| 996 | - dependency = builderFunc() as S; | ||
| 997 | - } | ||
| 998 | - return dependency; | ||
| 999 | - } else { | ||
| 1000 | - return builderFunc() as S; | ||
| 1001 | - } | ||
| 1002 | - } | ||
| 1003 | -} | ||
| 1004 | - | ||
| 1005 | -typedef _FcBuilderFunc<S> = S Function(); | ||
| 1006 | - | ||
| 1007 | -typedef _FcBuilderFuncAsync<S> = Future<S> Function(); |
| @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; | @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; | ||
| 2 | import 'package:get/get.dart'; | 2 | import 'package:get/get.dart'; |
| 3 | import 'package:get/src/routes/get_route.dart'; | 3 | import 'package:get/src/routes/get_route.dart'; |
| 4 | import 'package:get/src/routes/utils/parse_arguments.dart'; | 4 | import 'package:get/src/routes/utils/parse_arguments.dart'; |
| 5 | +import '../get_instance.dart'; | ||
| 5 | import 'root_controller.dart'; | 6 | import 'root_controller.dart'; |
| 6 | import 'smart_management.dart'; | 7 | import 'smart_management.dart'; |
| 7 | 8 | ||
| @@ -109,7 +110,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -109,7 +110,7 @@ class GetMaterialApp extends StatelessWidget { | ||
| 109 | /// workaround until they fix it, because the problem is with the 'Flutter engine', | 110 | /// workaround until they fix it, because the problem is with the 'Flutter engine', |
| 110 | /// which changes the initial route for an empty String, not the main Flutter, | 111 | /// which changes the initial route for an empty String, not the main Flutter, |
| 111 | /// so only Team can fix it. | 112 | /// so only Team can fix it. |
| 112 | - var parsedString = Get().getController.parse.split( | 113 | + var parsedString = Get.getController.parse.split( |
| 113 | (settings.name == '' || settings.name == null) | 114 | (settings.name == '' || settings.name == null) |
| 114 | ? (initialRoute ?? '/') | 115 | ? (initialRoute ?? '/') |
| 115 | : settings.name); | 116 | : settings.name); |
| @@ -123,7 +124,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -123,7 +124,7 @@ class GetMaterialApp extends StatelessWidget { | ||
| 123 | Map<String, GetRoute> newNamedRoutes = {}; | 124 | Map<String, GetRoute> newNamedRoutes = {}; |
| 124 | 125 | ||
| 125 | namedRoutes.forEach((key, value) { | 126 | namedRoutes.forEach((key, value) { |
| 126 | - String newName = Get().getController.parse.split(key).route; | 127 | + String newName = Get.getController.parse.split(key).route; |
| 127 | newNamedRoutes.addAll({newName: value}); | 128 | newNamedRoutes.addAll({newName: value}); |
| 128 | }); | 129 | }); |
| 129 | 130 | ||
| @@ -179,21 +180,21 @@ class GetMaterialApp extends StatelessWidget { | @@ -179,21 +180,21 @@ class GetMaterialApp extends StatelessWidget { | ||
| 179 | @override | 180 | @override |
| 180 | Widget build(BuildContext context) { | 181 | Widget build(BuildContext context) { |
| 181 | return GetBuilder<GetMaterialController>( | 182 | return GetBuilder<GetMaterialController>( |
| 182 | - init: Get().getController, | 183 | + init: Get.getController, |
| 183 | dispose: (d) { | 184 | dispose: (d) { |
| 184 | onDispose?.call(); | 185 | onDispose?.call(); |
| 185 | }, | 186 | }, |
| 186 | initState: (i) { | 187 | initState: (i) { |
| 187 | initialBinding?.dependencies(); | 188 | initialBinding?.dependencies(); |
| 188 | - Get().smartManagement = smartManagement; | 189 | + GetConfig.smartManagement = smartManagement; |
| 189 | onInit?.call(); | 190 | onInit?.call(); |
| 190 | if (namedRoutes != null) { | 191 | if (namedRoutes != null) { |
| 191 | namedRoutes.forEach((key, value) { | 192 | namedRoutes.forEach((key, value) { |
| 192 | - Get().getController.parse.addRoute(key); | 193 | + Get.getController.parse.addRoute(key); |
| 193 | }); | 194 | }); |
| 194 | } | 195 | } |
| 195 | Get.config( | 196 | Get.config( |
| 196 | - enableLog: enableLog ?? Get.isLogEnable, | 197 | + enableLog: enableLog ?? GetConfig.isLogEnable, |
| 197 | defaultTransition: defaultTransition ?? Get.defaultTransition, | 198 | defaultTransition: defaultTransition ?? Get.defaultTransition, |
| 198 | defaultOpaqueRoute: opaqueRoute ?? Get.isOpaqueRouteDefault, | 199 | defaultOpaqueRoute: opaqueRoute ?? Get.isOpaqueRouteDefault, |
| 199 | defaultPopGesture: popGesture ?? Get.isPopGestureEnable, | 200 | defaultPopGesture: popGesture ?? Get.isPopGestureEnable, |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | import 'package:get/src/root/smart_management.dart'; | 2 | import 'package:get/src/root/smart_management.dart'; |
| 3 | +import '../../get_instance.dart'; | ||
| 3 | import '../../get_main.dart'; | 4 | import '../../get_main.dart'; |
| 4 | 5 | ||
| 5 | class Routing { | 6 | class Routing { |
| @@ -44,13 +45,17 @@ class GetObserver extends NavigatorObserver { | @@ -44,13 +45,17 @@ class GetObserver extends NavigatorObserver { | ||
| 44 | @override | 45 | @override |
| 45 | void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { | 46 | void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { |
| 46 | if ('${route?.settings?.name}' == 'snackbar') { | 47 | if ('${route?.settings?.name}' == 'snackbar') { |
| 47 | - if (Get.isLogEnable) print("[OPEN SNACKBAR] ${route?.settings?.name}"); | 48 | + if (GetConfig.isLogEnable) |
| 49 | + print("[OPEN SNACKBAR] ${route?.settings?.name}"); | ||
| 48 | } else if ('${route?.settings?.name}' == 'bottomsheet') { | 50 | } else if ('${route?.settings?.name}' == 'bottomsheet') { |
| 49 | - if (Get.isLogEnable) print("[OPEN BOTTOMSHEET] ${route?.settings?.name}"); | 51 | + if (GetConfig.isLogEnable) |
| 52 | + print("[OPEN BOTTOMSHEET] ${route?.settings?.name}"); | ||
| 50 | } else if ('${route?.settings?.name}' == 'dialog') { | 53 | } else if ('${route?.settings?.name}' == 'dialog') { |
| 51 | - if (Get.isLogEnable) print("[OPEN DIALOG] ${route?.settings?.name}"); | 54 | + if (GetConfig.isLogEnable) |
| 55 | + print("[OPEN DIALOG] ${route?.settings?.name}"); | ||
| 52 | } else { | 56 | } else { |
| 53 | - if (Get.isLogEnable) print("[GOING TO ROUTE] ${route?.settings?.name}"); | 57 | + if (GetConfig.isLogEnable) |
| 58 | + print("[GOING TO ROUTE] ${route?.settings?.name}"); | ||
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | isSnackbar = '${route?.settings?.name}' == 'snackbar'; | 61 | isSnackbar = '${route?.settings?.name}' == 'snackbar'; |
| @@ -76,6 +81,7 @@ class GetObserver extends NavigatorObserver { | @@ -76,6 +81,7 @@ class GetObserver extends NavigatorObserver { | ||
| 76 | if (routing != null) { | 81 | if (routing != null) { |
| 77 | routing(routeSend); | 82 | routing(routeSend); |
| 78 | } | 83 | } |
| 84 | + GetConfig.currentRoute = current; | ||
| 79 | Get.setRouting(routeSend); | 85 | Get.setRouting(routeSend); |
| 80 | } | 86 | } |
| 81 | 87 | ||
| @@ -84,18 +90,20 @@ class GetObserver extends NavigatorObserver { | @@ -84,18 +90,20 @@ class GetObserver extends NavigatorObserver { | ||
| 84 | super.didPop(route, previousRoute); | 90 | super.didPop(route, previousRoute); |
| 85 | 91 | ||
| 86 | if ('${route?.settings?.name}' == 'snackbar') { | 92 | if ('${route?.settings?.name}' == 'snackbar') { |
| 87 | - if (Get.isLogEnable) print("[CLOSE SNACKBAR] ${route?.settings?.name}"); | 93 | + if (GetConfig.isLogEnable) |
| 94 | + print("[CLOSE SNACKBAR] ${route?.settings?.name}"); | ||
| 88 | } else if ('${route?.settings?.name}' == 'bottomsheet') { | 95 | } else if ('${route?.settings?.name}' == 'bottomsheet') { |
| 89 | - if (Get.isLogEnable) | 96 | + if (GetConfig.isLogEnable) |
| 90 | print("[CLOSE BOTTOMSHEET] ${route?.settings?.name}"); | 97 | print("[CLOSE BOTTOMSHEET] ${route?.settings?.name}"); |
| 91 | } else if ('${route?.settings?.name}' == 'dialog') { | 98 | } else if ('${route?.settings?.name}' == 'dialog') { |
| 92 | - if (Get.isLogEnable) print("[CLOSE DIALOG] ${route?.settings?.name}"); | 99 | + if (GetConfig.isLogEnable) |
| 100 | + print("[CLOSE DIALOG] ${route?.settings?.name}"); | ||
| 93 | } else { | 101 | } else { |
| 94 | - if (Get.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}"); | 102 | + if (GetConfig.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}"); |
| 95 | } | 103 | } |
| 96 | 104 | ||
| 97 | - if (Get().smartManagement != SmartManagement.onlyBuilder) { | ||
| 98 | - Get().removeDependencyByRoute("${route?.settings?.name}"); | 105 | + if (GetConfig.smartManagement != SmartManagement.onlyBuilder) { |
| 106 | + GetInstance().removeDependencyByRoute("${route?.settings?.name}"); | ||
| 99 | } | 107 | } |
| 100 | 108 | ||
| 101 | isSnackbar = false; | 109 | isSnackbar = false; |
| @@ -122,17 +130,19 @@ class GetObserver extends NavigatorObserver { | @@ -122,17 +130,19 @@ class GetObserver extends NavigatorObserver { | ||
| 122 | if (routing != null) { | 130 | if (routing != null) { |
| 123 | routing(routeSend); | 131 | routing(routeSend); |
| 124 | } | 132 | } |
| 133 | + GetConfig.currentRoute = current; | ||
| 125 | Get.setRouting(routeSend); | 134 | Get.setRouting(routeSend); |
| 126 | } | 135 | } |
| 127 | 136 | ||
| 128 | @override | 137 | @override |
| 129 | void didReplace({Route newRoute, Route oldRoute}) { | 138 | void didReplace({Route newRoute, Route oldRoute}) { |
| 130 | super.didReplace(newRoute: newRoute, oldRoute: oldRoute); | 139 | super.didReplace(newRoute: newRoute, oldRoute: oldRoute); |
| 131 | - if (Get.isLogEnable) print("[REPLACE ROUTE] ${oldRoute?.settings?.name}"); | ||
| 132 | - if (Get.isLogEnable) print("[NEW ROUTE] ${newRoute?.settings?.name}"); | 140 | + if (GetConfig.isLogEnable) |
| 141 | + print("[REPLACE ROUTE] ${oldRoute?.settings?.name}"); | ||
| 142 | + if (GetConfig.isLogEnable) print("[NEW ROUTE] ${newRoute?.settings?.name}"); | ||
| 133 | 143 | ||
| 134 | - if (Get().smartManagement == SmartManagement.full) { | ||
| 135 | - Get().removeDependencyByRoute("${oldRoute?.settings?.name}"); | 144 | + if (GetConfig.smartManagement == SmartManagement.full) { |
| 145 | + GetInstance().removeDependencyByRoute("${oldRoute?.settings?.name}"); | ||
| 136 | } | 146 | } |
| 137 | 147 | ||
| 138 | isSnackbar = false; | 148 | isSnackbar = false; |
| @@ -155,16 +165,18 @@ class GetObserver extends NavigatorObserver { | @@ -155,16 +165,18 @@ class GetObserver extends NavigatorObserver { | ||
| 155 | if (routing != null) { | 165 | if (routing != null) { |
| 156 | routing(routeSend); | 166 | routing(routeSend); |
| 157 | } | 167 | } |
| 168 | + GetConfig.currentRoute = current; | ||
| 158 | Get.setRouting(routeSend); | 169 | Get.setRouting(routeSend); |
| 159 | } | 170 | } |
| 160 | 171 | ||
| 161 | @override | 172 | @override |
| 162 | void didRemove(Route route, Route previousRoute) { | 173 | void didRemove(Route route, Route previousRoute) { |
| 163 | super.didRemove(route, previousRoute); | 174 | super.didRemove(route, previousRoute); |
| 164 | - if (Get.isLogEnable) print("[REMOVING ROUTE] ${route?.settings?.name}"); | 175 | + if (GetConfig.isLogEnable) |
| 176 | + print("[REMOVING ROUTE] ${route?.settings?.name}"); | ||
| 165 | 177 | ||
| 166 | - if (Get().smartManagement == SmartManagement.full) { | ||
| 167 | - Get().removeDependencyByRoute("${route?.settings?.name}"); | 178 | + if (GetConfig.smartManagement == SmartManagement.full) { |
| 179 | + GetInstance().removeDependencyByRoute("${route?.settings?.name}"); | ||
| 168 | } | 180 | } |
| 169 | 181 | ||
| 170 | final routeSend = Routing( | 182 | final routeSend = Routing( |
| @@ -184,6 +196,7 @@ class GetObserver extends NavigatorObserver { | @@ -184,6 +196,7 @@ class GetObserver extends NavigatorObserver { | ||
| 184 | if (routing != null) { | 196 | if (routing != null) { |
| 185 | routing(routeSend); | 197 | routing(routeSend); |
| 186 | } | 198 | } |
| 199 | + GetConfig.currentRoute = current; | ||
| 187 | Get.setRouting(routeSend); | 200 | Get.setRouting(routeSend); |
| 188 | } | 201 | } |
| 189 | } | 202 | } |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | -import 'package:get/src/get_main.dart'; | ||
| 3 | import 'package:get/src/root/smart_management.dart'; | 2 | import 'package:get/src/root/smart_management.dart'; |
| 3 | +import '../get_instance.dart'; | ||
| 4 | import 'rx_impl.dart'; | 4 | import 'rx_impl.dart'; |
| 5 | import 'rx_interface.dart'; | 5 | import 'rx_interface.dart'; |
| 6 | 6 | ||
| @@ -25,35 +25,32 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | @@ -25,35 +25,32 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | ||
| 25 | this.init, | 25 | this.init, |
| 26 | // this.streamController | 26 | // this.streamController |
| 27 | }); | 27 | }); |
| 28 | - _GetXState<T> createState() => _GetXState<T>(); | 28 | + GetImplXState<T> createState() => GetImplXState<T>(); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | -class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | 31 | +class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> { |
| 32 | RxInterface _observer; | 32 | RxInterface _observer; |
| 33 | T controller; | 33 | T controller; |
| 34 | bool isCreator = false; | 34 | bool isCreator = false; |
| 35 | 35 | ||
| 36 | - _GetXState() { | ||
| 37 | - _observer = Rx(); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | @override | 36 | @override |
| 41 | void initState() { | 37 | void initState() { |
| 42 | - bool isPrepared = Get.isPrepared<T>(); | ||
| 43 | - bool isRegistred = Get.isRegistred<T>(); | 38 | + _observer = Rx(); |
| 39 | + bool isPrepared = GetInstance().isPrepared<T>(); | ||
| 40 | + bool isRegistred = GetInstance().isRegistred<T>(); | ||
| 44 | if (widget.global) { | 41 | if (widget.global) { |
| 45 | if (isPrepared) { | 42 | if (isPrepared) { |
| 46 | - if (Get().smartManagement != SmartManagement.keepFactory) { | 43 | + if (GetConfig.smartManagement != SmartManagement.keepFactory) { |
| 47 | isCreator = true; | 44 | isCreator = true; |
| 48 | } | 45 | } |
| 49 | - controller = Get.find<T>(); | 46 | + controller = GetInstance().find<T>(); |
| 50 | } else if (isRegistred) { | 47 | } else if (isRegistred) { |
| 51 | - controller = Get.find<T>(); | 48 | + controller = GetInstance().find<T>(); |
| 52 | isCreator = false; | 49 | isCreator = false; |
| 53 | } else { | 50 | } else { |
| 54 | controller = widget.init; | 51 | controller = widget.init; |
| 55 | isCreator = true; | 52 | isCreator = true; |
| 56 | - Get.put<T>(controller); | 53 | + GetInstance().put<T>(controller); |
| 57 | } | 54 | } |
| 58 | } else { | 55 | } else { |
| 59 | controller = widget.init; | 56 | controller = widget.init; |
| @@ -61,7 +58,7 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -61,7 +58,7 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
| 61 | controller?.onStart(); | 58 | controller?.onStart(); |
| 62 | } | 59 | } |
| 63 | if (widget.initState != null) widget.initState(this); | 60 | if (widget.initState != null) widget.initState(this); |
| 64 | - if (isCreator && Get().smartManagement == SmartManagement.onlyBuilder) { | 61 | + if (isCreator && GetConfig.smartManagement == SmartManagement.onlyBuilder) { |
| 65 | controller?.onStart(); | 62 | controller?.onStart(); |
| 66 | } | 63 | } |
| 67 | _observer.subject.stream.listen((data) => setState(() {})); | 64 | _observer.subject.stream.listen((data) => setState(() {})); |
| @@ -72,8 +69,8 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -72,8 +69,8 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
| 72 | void dispose() { | 69 | void dispose() { |
| 73 | if (widget.dispose != null) widget.dispose(this); | 70 | if (widget.dispose != null) widget.dispose(this); |
| 74 | if (isCreator || widget.assignId) { | 71 | if (isCreator || widget.assignId) { |
| 75 | - if (widget.autoRemove && Get.isRegistred<T>()) { | ||
| 76 | - Get.delete<T>(); | 72 | + if (widget.autoRemove && GetInstance().isRegistred<T>()) { |
| 73 | + GetInstance().delete<T>(); | ||
| 77 | } | 74 | } |
| 78 | } | 75 | } |
| 79 | 76 | ||
| @@ -83,12 +80,14 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -83,12 +80,14 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
| 83 | super.dispose(); | 80 | super.dispose(); |
| 84 | } | 81 | } |
| 85 | 82 | ||
| 86 | - @override | ||
| 87 | - Widget build(BuildContext context) { | 83 | + Widget get notifyChilds { |
| 88 | final observer = getObs; | 84 | final observer = getObs; |
| 89 | - getObs = this._observer; | 85 | + getObs = _observer; |
| 90 | final result = widget.builder(controller); | 86 | final result = widget.builder(controller); |
| 91 | getObs = observer; | 87 | getObs = observer; |
| 92 | return result; | 88 | return result; |
| 93 | } | 89 | } |
| 90 | + | ||
| 91 | + @override | ||
| 92 | + Widget build(BuildContext context) => notifyChilds; | ||
| 94 | } | 93 | } |
| @@ -341,6 +341,11 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -341,6 +341,11 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
| 341 | subject.add(null); | 341 | subject.add(null); |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | + void sort([int compare(E a, E b)]) { | ||
| 345 | + _list.sort(); | ||
| 346 | + subject.add(null); | ||
| 347 | + } | ||
| 348 | + | ||
| 344 | close() { | 349 | close() { |
| 345 | _subscriptions.forEach((observable, subscription) { | 350 | _subscriptions.forEach((observable, subscription) { |
| 346 | subscription.cancel(); | 351 | subscription.cancel(); |
| @@ -53,5 +53,5 @@ abstract class DisposableInterface { | @@ -53,5 +53,5 @@ abstract class DisposableInterface { | ||
| 53 | 53 | ||
| 54 | /// Called before the onDelete method. onClose is used to close events | 54 | /// Called before the onDelete method. onClose is used to close events |
| 55 | /// before the controller is destroyed, such as closing streams, for example. | 55 | /// before the controller is destroyed, such as closing streams, for example. |
| 56 | - void onClose() async {} | 56 | + onClose() async {} |
| 57 | } | 57 | } |
| 1 | -import 'package:flutter/material.dart'; | ||
| 2 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | +import 'package:get/src/get_instance.dart'; | ||
| 3 | import 'package:get/src/root/smart_management.dart'; | 3 | import 'package:get/src/root/smart_management.dart'; |
| 4 | import 'package:get/src/rx/rx_interface.dart'; | 4 | import 'package:get/src/rx/rx_interface.dart'; |
| 5 | -import '../get_main.dart'; | ||
| 6 | 5 | ||
| 7 | class GetController extends DisposableInterface { | 6 | class GetController extends DisposableInterface { |
| 8 | - List<RealState> _allStates = []; | 7 | + List<Updater> _updaters = []; |
| 8 | + | ||
| 9 | + /// Update GetBuilder with update(); | ||
| 10 | + void update([List<String> ids, bool condition = true]) { | ||
| 11 | + if (!condition) return; | ||
| 12 | + (ids == null) | ||
| 13 | + ? _updaters.forEach((rs) { | ||
| 14 | + rs.updater(() {}); | ||
| 15 | + }) | ||
| 16 | + : _updaters | ||
| 17 | + .where((element) => ids.contains(element.id)) | ||
| 18 | + .forEach((rs) => rs.updater(() {})); | ||
| 19 | + } | ||
| 9 | 20 | ||
| 10 | - @override | ||
| 11 | void onInit() async {} | 21 | void onInit() async {} |
| 12 | 22 | ||
| 13 | - @override | ||
| 14 | void onReady() async {} | 23 | void onReady() async {} |
| 15 | 24 | ||
| 16 | - @override | ||
| 17 | void onClose() async {} | 25 | void onClose() async {} |
| 18 | - | ||
| 19 | - /// Update GetBuilder with update(); | ||
| 20 | - void update([List<String> ids, bool condition = true]) { | ||
| 21 | - if (!condition) return; | ||
| 22 | - | ||
| 23 | - if (ids == null) { | ||
| 24 | - _allStates.forEach((rs) { | ||
| 25 | - rs.updater(() {}); | ||
| 26 | - }); | ||
| 27 | - } else { | ||
| 28 | - ids.forEach( | ||
| 29 | - (s) { | ||
| 30 | - _allStates.forEach((rs) { | ||
| 31 | - if (rs.id == s) rs.updater(() {}); | ||
| 32 | - }); | ||
| 33 | - }, | ||
| 34 | - ); | ||
| 35 | - } | ||
| 36 | - } | ||
| 37 | } | 26 | } |
| 38 | 27 | ||
| 39 | class GetBuilder<T extends GetController> extends StatefulWidget { | 28 | class GetBuilder<T extends GetController> extends StatefulWidget { |
| @@ -41,6 +30,7 @@ class GetBuilder<T extends GetController> extends StatefulWidget { | @@ -41,6 +30,7 @@ class GetBuilder<T extends GetController> extends StatefulWidget { | ||
| 41 | final Widget Function(T) builder; | 30 | final Widget Function(T) builder; |
| 42 | final bool global; | 31 | final bool global; |
| 43 | final String id; | 32 | final String id; |
| 33 | + final String tag; | ||
| 44 | final bool autoRemove; | 34 | final bool autoRemove; |
| 45 | final bool assignId; | 35 | final bool assignId; |
| 46 | final void Function(State state) initState, dispose, didChangeDependencies; | 36 | final void Function(State state) initState, dispose, didChangeDependencies; |
| @@ -54,6 +44,7 @@ class GetBuilder<T extends GetController> extends StatefulWidget { | @@ -54,6 +44,7 @@ class GetBuilder<T extends GetController> extends StatefulWidget { | ||
| 54 | this.autoRemove = true, | 44 | this.autoRemove = true, |
| 55 | this.assignId = false, | 45 | this.assignId = false, |
| 56 | this.initState, | 46 | this.initState, |
| 47 | + this.tag, | ||
| 57 | this.dispose, | 48 | this.dispose, |
| 58 | this.id, | 49 | this.id, |
| 59 | this.didChangeDependencies, | 50 | this.didChangeDependencies, |
| @@ -66,44 +57,44 @@ class GetBuilder<T extends GetController> extends StatefulWidget { | @@ -66,44 +57,44 @@ class GetBuilder<T extends GetController> extends StatefulWidget { | ||
| 66 | 57 | ||
| 67 | class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | 58 | class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { |
| 68 | T controller; | 59 | T controller; |
| 69 | - RealState real; | 60 | + Updater real; |
| 70 | bool isCreator = false; | 61 | bool isCreator = false; |
| 71 | @override | 62 | @override |
| 72 | void initState() { | 63 | void initState() { |
| 73 | super.initState(); | 64 | super.initState(); |
| 74 | 65 | ||
| 75 | if (widget.global) { | 66 | if (widget.global) { |
| 76 | - bool isPrepared = Get.isPrepared<T>(); | ||
| 77 | - bool isRegistred = Get.isRegistred<T>(); | 67 | + bool isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); |
| 68 | + bool isRegistred = GetInstance().isRegistred<T>(tag: widget.tag); | ||
| 78 | 69 | ||
| 79 | if (isPrepared) { | 70 | if (isPrepared) { |
| 80 | - if (Get().smartManagement != SmartManagement.keepFactory) { | 71 | + if (GetConfig.smartManagement != SmartManagement.keepFactory) { |
| 81 | isCreator = true; | 72 | isCreator = true; |
| 82 | } | 73 | } |
| 83 | - controller = Get.find<T>(); | ||
| 84 | - real = RealState(updater: setState, id: widget.id); | ||
| 85 | - controller._allStates.add(real); | 74 | + controller = GetInstance().find<T>(tag: widget.tag); |
| 75 | + real = Updater(updater: setState, id: widget.id); | ||
| 76 | + controller._updaters.add(real); | ||
| 86 | } else if (isRegistred) { | 77 | } else if (isRegistred) { |
| 87 | - controller = Get.find<T>(); | 78 | + controller = GetInstance().find<T>(tag: widget.tag); |
| 88 | isCreator = false; | 79 | isCreator = false; |
| 89 | - real = RealState(updater: setState, id: widget.id); | ||
| 90 | - controller._allStates.add(real); | 80 | + real = Updater(updater: setState, id: widget.id); |
| 81 | + controller._updaters.add(real); | ||
| 91 | } else { | 82 | } else { |
| 92 | controller = widget.init; | 83 | controller = widget.init; |
| 93 | isCreator = true; | 84 | isCreator = true; |
| 94 | - real = RealState(updater: setState, id: widget.id); | ||
| 95 | - controller._allStates.add(real); | ||
| 96 | - Get.put<T>(controller); | 85 | + real = Updater(updater: setState, id: widget.id); |
| 86 | + controller._updaters.add(real); | ||
| 87 | + GetInstance().put<T>(controller, tag: widget.tag); | ||
| 97 | } | 88 | } |
| 98 | } else { | 89 | } else { |
| 99 | controller = widget.init; | 90 | controller = widget.init; |
| 100 | isCreator = true; | 91 | isCreator = true; |
| 101 | - real = RealState(updater: setState, id: widget.id); | ||
| 102 | - controller._allStates.add(real); | 92 | + real = Updater(updater: setState, id: widget.id); |
| 93 | + controller._updaters.add(real); | ||
| 103 | controller?.onStart(); | 94 | controller?.onStart(); |
| 104 | } | 95 | } |
| 105 | if (widget.initState != null) widget.initState(this); | 96 | if (widget.initState != null) widget.initState(this); |
| 106 | - if (isCreator && Get().smartManagement == SmartManagement.onlyBuilder) { | 97 | + if (isCreator && GetConfig.smartManagement == SmartManagement.onlyBuilder) { |
| 107 | controller?.onStart(); | 98 | controller?.onStart(); |
| 108 | } | 99 | } |
| 109 | } | 100 | } |
| @@ -113,12 +104,12 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -113,12 +104,12 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
| 113 | super.dispose(); | 104 | super.dispose(); |
| 114 | if (widget.dispose != null) widget.dispose(this); | 105 | if (widget.dispose != null) widget.dispose(this); |
| 115 | if (isCreator || widget.assignId) { | 106 | if (isCreator || widget.assignId) { |
| 116 | - if (widget.autoRemove && Get.isRegistred<T>()) { | ||
| 117 | - controller._allStates.remove(real); | ||
| 118 | - Get.delete<T>(); | 107 | + if (widget.autoRemove && GetInstance().isRegistred<T>(tag: widget.tag)) { |
| 108 | + controller._updaters.remove(real); | ||
| 109 | + GetInstance().delete<T>(tag: widget.tag); | ||
| 119 | } | 110 | } |
| 120 | } else { | 111 | } else { |
| 121 | - controller._allStates.remove(real); | 112 | + controller._updaters.remove(real); |
| 122 | } | 113 | } |
| 123 | } | 114 | } |
| 124 | 115 | ||
| @@ -141,10 +132,8 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -141,10 +132,8 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
| 141 | } | 132 | } |
| 142 | } | 133 | } |
| 143 | 134 | ||
| 144 | -typedef ShouldRebuild<T> = bool Function(T previous, T next); | ||
| 145 | - | ||
| 146 | -class RealState { | 135 | +class Updater { |
| 147 | final StateSetter updater; | 136 | final StateSetter updater; |
| 148 | final String id; | 137 | final String id; |
| 149 | - const RealState({this.updater, this.id}); | 138 | + const Updater({this.updater, this.id}); |
| 150 | } | 139 | } |
lib/src/typedefs/typedefs.dart
0 → 100644
| 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 | name: get | 1 | name: get |
| 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. | 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. |
| 3 | -version: 2.12.6 | 3 | +version: 2.13.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