Showing
14 changed files
with
300 additions
and
75 deletions
| 1 | library get; | 1 | library get; | 
| 2 | 2 | ||
| 3 | -export 'src/instance/instance_manager.dart'; | ||
| 4 | -export 'src/navigation/route_manager.dart'; | ||
| 5 | -export 'src/state_manager/state_manager.dart'; | ||
| 6 | -export 'src/utils/utils.dart'; | 3 | +export 'instance_manager.dart'; | 
| 4 | +export 'route_manager.dart'; | ||
| 5 | +export 'state_manager.dart'; | ||
| 6 | +export 'utils.dart'; | 
lib/instance_manager.dart
0 → 100644
lib/route_manager.dart
0 → 100644
| 1 | +export 'src/navigation/routes/custom_transition.dart'; | ||
| 2 | +export 'src/navigation/routes/transitions_type.dart'; | ||
| 3 | +export 'src/navigation/routes/get_route.dart'; | ||
| 4 | +export 'src/navigation/routes/default_route.dart'; | ||
| 5 | +export 'src/navigation/routes/observers/route_observer.dart'; | ||
| 6 | +export 'src/navigation/root/root_widget.dart'; | ||
| 7 | +export 'src/navigation/snackbar/snack_route.dart'; | ||
| 8 | +export 'src/navigation/bottomsheet/bottomsheet.dart'; | ||
| 9 | +export 'src/navigation/snackbar/snack.dart'; | ||
| 10 | +export 'src/get_main.dart'; | ||
| 11 | +export 'src/navigation/routes/default_route.dart'; | ||
| 12 | +export 'src/navigation/root/smart_management.dart'; | ||
| 13 | +export 'src/navigation/extension_navigation.dart'; | 
| @@ -4,7 +4,7 @@ import 'navigation/root/root_controller.dart'; | @@ -4,7 +4,7 @@ import 'navigation/root/root_controller.dart'; | ||
| 4 | import 'navigation/routes/custom_transition.dart'; | 4 | import 'navigation/routes/custom_transition.dart'; | 
| 5 | import 'navigation/routes/observers/route_observer.dart'; | 5 | import 'navigation/routes/observers/route_observer.dart'; | 
| 6 | import 'navigation/routes/transitions_type.dart'; | 6 | import 'navigation/routes/transitions_type.dart'; | 
| 7 | -import 'utils/utils.dart'; | 7 | +import '../utils.dart'; | 
| 8 | 8 | ||
| 9 | ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | 9 | ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | 
| 10 | ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | 10 | ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | 
| @@ -33,7 +33,7 @@ abstract class GetInterface { | @@ -33,7 +33,7 @@ abstract class GetInterface { | ||
| 33 | GetMaterialController getxController = GetMaterialController(); | 33 | GetMaterialController getxController = GetMaterialController(); | 
| 34 | 34 | ||
| 35 | Locale locale; | 35 | Locale locale; | 
| 36 | - | 36 | + | 
| 37 | Locale fallbackLocale; | 37 | Locale fallbackLocale; | 
| 38 | 38 | ||
| 39 | GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); | 39 | GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); | 
| @@ -75,8 +75,8 @@ class GetInstance { | @@ -75,8 +75,8 @@ class GetInstance { | ||
| 75 | assert(builder != null); | 75 | assert(builder != null); | 
| 76 | String key = _getKey(S, name); | 76 | String key = _getKey(S, name); | 
| 77 | 77 | ||
| 78 | - GetConfig._singl | ||
| 79 | - .putIfAbsent(key, () => FcBuilder<S>(isSingleton, builder, permanent)); | 78 | + GetConfig._singl.putIfAbsent( | 
| 79 | + key, () => FcBuilder<S>(isSingleton, builder, permanent, false)); | ||
| 80 | } | 80 | } | 
| 81 | 81 | ||
| 82 | Future<void> removeDependencyByRoute(String routeName) async { | 82 | Future<void> removeDependencyByRoute(String routeName) async { | 
| @@ -97,9 +97,17 @@ class GetInstance { | @@ -97,9 +97,17 @@ class GetInstance { | ||
| 97 | keysToRemove.clear(); | 97 | keysToRemove.clear(); | 
| 98 | } | 98 | } | 
| 99 | 99 | ||
| 100 | - bool isDependencyInit<S>({String name}) { | 100 | + bool initDependencies<S>({String name}) { | 
| 101 | String key = _getKey(S, name); | 101 | String key = _getKey(S, name); | 
| 102 | - return GetConfig.routesKey.containsKey(key); | 102 | + bool isInit = GetConfig._singl[key].isInit; | 
| 103 | + if (!isInit) { | ||
| 104 | + startController<S>(tag: name); | ||
| 105 | + GetConfig._singl[key].isInit = true; | ||
| 106 | + if (GetConfig.smartManagement != SmartManagement.onlyBuilder) { | ||
| 107 | + registerRouteInstance<S>(tag: name); | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + return true; | ||
| 103 | } | 111 | } | 
| 104 | 112 | ||
| 105 | void registerRouteInstance<S>({String tag}) { | 113 | void registerRouteInstance<S>({String tag}) { | 
| @@ -112,7 +120,7 @@ class GetInstance { | @@ -112,7 +120,7 @@ class GetInstance { | ||
| 112 | return GetConfig._singl[key].getSependency() as S; | 120 | return GetConfig._singl[key].getSependency() as S; | 
| 113 | } | 121 | } | 
| 114 | 122 | ||
| 115 | - void initController<S>({String tag}) { | 123 | + void startController<S>({String tag}) { | 
| 116 | String key = _getKey(S, tag); | 124 | String key = _getKey(S, tag); | 
| 117 | final i = GetConfig._singl[key].getSependency(); | 125 | final i = GetConfig._singl[key].getSependency(); | 
| 118 | 126 | ||
| @@ -146,14 +154,8 @@ class GetInstance { | @@ -146,14 +154,8 @@ class GetInstance { | ||
| 146 | /// Find a instance from required class | 154 | /// Find a instance from required class | 
| 147 | S find<S>({String tag, FcBuilderFunc<S> instance}) { | 155 | S find<S>({String tag, FcBuilderFunc<S> instance}) { | 
| 148 | String key = _getKey(S, tag); | 156 | String key = _getKey(S, tag); | 
| 149 | - bool callInit = false; | ||
| 150 | - if (isRegistred<S>(tag: tag)) { | ||
| 151 | - if (!isDependencyInit<S>() && | ||
| 152 | - GetConfig.smartManagement != SmartManagement.onlyBuilder) { | ||
| 153 | - registerRouteInstance<S>(tag: tag); | ||
| 154 | - callInit = true; | ||
| 155 | - } | ||
| 156 | 157 | ||
| 158 | + if (isRegistred<S>(tag: tag)) { | ||
| 157 | FcBuilder builder = GetConfig._singl[key] as FcBuilder; | 159 | FcBuilder builder = GetConfig._singl[key] as FcBuilder; | 
| 158 | if (builder == null) { | 160 | if (builder == null) { | 
| 159 | if (tag == null) { | 161 | if (tag == null) { | 
| @@ -162,9 +164,7 @@ class GetInstance { | @@ -162,9 +164,7 @@ class GetInstance { | ||
| 162 | throw "class ${S.toString()} with tag '$tag' is not register"; | 164 | throw "class ${S.toString()} with tag '$tag' is not register"; | 
| 163 | } | 165 | } | 
| 164 | } | 166 | } | 
| 165 | - if (callInit) { | ||
| 166 | - initController<S>(tag: tag); | ||
| 167 | - } | 167 | + initDependencies<S>(); | 
| 168 | 168 | ||
| 169 | return GetConfig._singl[key].getSependency() as S; | 169 | return GetConfig._singl[key].getSependency() as S; | 
| 170 | } else { | 170 | } else { | 
| @@ -175,21 +175,13 @@ class GetInstance { | @@ -175,21 +175,13 @@ class GetInstance { | ||
| 175 | print('[GETX] $S instance was created at that time'); | 175 | print('[GETX] $S instance was created at that time'); | 
| 176 | S _value = put<S>(GetConfig._factory[key].builder() as S); | 176 | S _value = put<S>(GetConfig._factory[key].builder() as S); | 
| 177 | 177 | ||
| 178 | - if (!isDependencyInit<S>() && | ||
| 179 | - GetConfig.smartManagement != SmartManagement.onlyBuilder) { | ||
| 180 | - registerRouteInstance<S>(tag: tag); | ||
| 181 | - callInit = true; | ||
| 182 | - } | 178 | + initDependencies<S>(); | 
| 183 | 179 | ||
| 184 | - if (GetConfig.smartManagement != SmartManagement.keepFactory) { | ||
| 185 | - if (!GetConfig._factory[key].fenix) { | ||
| 186 | - GetConfig._factory.remove(key); | ||
| 187 | - } | 180 | + if (GetConfig.smartManagement != SmartManagement.keepFactory && | 
| 181 | + !GetConfig._factory[key].fenix) { | ||
| 182 | + GetConfig._factory.remove(key); | ||
| 188 | } | 183 | } | 
| 189 | 184 | ||
| 190 | - if (callInit) { | ||
| 191 | - initController<S>(tag: tag); | ||
| 192 | - } | ||
| 193 | return _value; | 185 | return _value; | 
| 194 | } | 186 | } | 
| 195 | } | 187 | } | 
| @@ -263,8 +255,9 @@ class FcBuilder<S> { | @@ -263,8 +255,9 @@ class FcBuilder<S> { | ||
| 263 | FcBuilderFunc builderFunc; | 255 | FcBuilderFunc builderFunc; | 
| 264 | S dependency; | 256 | S dependency; | 
| 265 | bool permanent = false; | 257 | bool permanent = false; | 
| 258 | + bool isInit = false; | ||
| 266 | 259 | ||
| 267 | - FcBuilder(this.isSingleton, this.builderFunc, this.permanent); | 260 | + FcBuilder(this.isSingleton, this.builderFunc, this.permanent, this.isInit); | 
| 268 | 261 | ||
| 269 | S getSependency() { | 262 | S getSependency() { | 
| 270 | if (isSingleton) { | 263 | if (isSingleton) { | 
| 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/src/get_interface.dart'; | 3 | import 'package:get/src/get_interface.dart'; | 
| 4 | -import 'package:get/src/instance/instance_manager.dart'; | ||
| 5 | -import 'package:get/src/navigation/route_manager.dart'; | ||
| 6 | - | 4 | +import 'package:get/instance_manager.dart'; | 
| 5 | +import 'package:get/route_manager.dart'; | ||
| 7 | import 'root/parse_route.dart'; | 6 | import 'root/parse_route.dart'; | 
| 8 | import 'routes/bindings_interface.dart'; | 7 | import 'routes/bindings_interface.dart'; | 
| 9 | 8 | 
| @@ -281,7 +281,8 @@ extension Trans on String { | @@ -281,7 +281,8 @@ extension Trans on String { | ||
| 281 | Get.translations[Get.locale.languageCode].containsKey(this)) { | 281 | Get.translations[Get.locale.languageCode].containsKey(this)) { | 
| 282 | return Get.translations[Get.locale.languageCode][this]; | 282 | return Get.translations[Get.locale.languageCode][this]; | 
| 283 | // If there is no corresponding language or corresponding key, return the key. | 283 | // If there is no corresponding language or corresponding key, return the key. | 
| 284 | - } else if (Get.fallbackLocale != null && Get.translations.containsKey( | 284 | + } else if (Get.fallbackLocale != null && | 
| 285 | + Get.translations.containsKey( | ||
| 285 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}") && | 286 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}") && | 
| 286 | Get.translations[ | 287 | Get.translations[ | 
| 287 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | 288 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | 
| @@ -3,10 +3,10 @@ import 'dart:ui' show lerpDouble; | @@ -3,10 +3,10 @@ import 'dart:ui' show lerpDouble; | ||
| 3 | import 'package:flutter/cupertino.dart'; | 3 | import 'package:flutter/cupertino.dart'; | 
| 4 | import 'package:flutter/gestures.dart'; | 4 | import 'package:flutter/gestures.dart'; | 
| 5 | import 'package:flutter/material.dart'; | 5 | import 'package:flutter/material.dart'; | 
| 6 | -import 'package:get/src/navigation/route_manager.dart'; | 6 | +import 'package:get/route_manager.dart'; | 
| 7 | import 'package:get/src/get_main.dart'; | 7 | import 'package:get/src/get_main.dart'; | 
| 8 | import 'package:get/src/instance/get_instance.dart'; | 8 | import 'package:get/src/instance/get_instance.dart'; | 
| 9 | -import 'package:get/src/utils/utils.dart'; | 9 | +import 'package:get/utils.dart'; | 
| 10 | import 'bindings_interface.dart'; | 10 | import 'bindings_interface.dart'; | 
| 11 | import 'custom_transition.dart'; | 11 | import 'custom_transition.dart'; | 
| 12 | import 'default_transitions.dart'; | 12 | import 'default_transitions.dart'; | 
| @@ -4,21 +4,40 @@ import 'package:get/src/instance/get_instance.dart'; | @@ -4,21 +4,40 @@ import 'package:get/src/instance/get_instance.dart'; | ||
| 4 | import 'package:get/src/navigation/root/smart_management.dart'; | 4 | import 'package:get/src/navigation/root/smart_management.dart'; | 
| 5 | import 'package:get/src/state_manager/rx/rx_interface.dart'; | 5 | import 'package:get/src/state_manager/rx/rx_interface.dart'; | 
| 6 | 6 | ||
| 7 | +typedef Disposer = void Function(); | ||
| 8 | + | ||
| 7 | class GetxController extends DisposableInterface { | 9 | class GetxController extends DisposableInterface { | 
| 8 | - final HashSet<UpdaterBuilder> _updaters = HashSet<UpdaterBuilder>(); | 10 | + final HashSet<StateSetter> _updaters = HashSet<StateSetter>(); | 
| 11 | + | ||
| 12 | + final HashMap<String, StateSetter> _updatersIds = | ||
| 13 | + HashMap<String, StateSetter>(); | ||
| 9 | 14 | ||
| 10 | /// Update GetBuilder with update(); | 15 | /// Update GetBuilder with update(); | 
| 11 | void update([List<String> ids, bool condition = true]) { | 16 | void update([List<String> ids, bool condition = true]) { | 
| 12 | if (!condition) return; | 17 | if (!condition) return; | 
| 13 | (ids == null) | 18 | (ids == null) | 
| 14 | - ? _updaters.forEach((rs) { | ||
| 15 | - rs().updater(() {}); | ||
| 16 | - }) | ||
| 17 | - : _updaters | ||
| 18 | - .where((element) => ids.contains(element().id)) | ||
| 19 | - .forEach((rs) => rs().updater(() {})); | 19 | + ? _updaters.forEach((rs) => rs(() {})) | 
| 20 | + : ids.forEach((element) { | ||
| 21 | + _updatersIds[element]?.call(() {}); | ||
| 22 | + }); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + Disposer addListener(StateSetter listener) { | ||
| 26 | + _updaters.add(listener); | ||
| 27 | + return () => _updaters.remove(listener); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + // void removeListener(StateSetter listener) { | ||
| 31 | + // _updaters.remove(listener); | ||
| 32 | + // } | ||
| 33 | + | ||
| 34 | + Disposer addListenerId(String key, StateSetter listener) { | ||
| 35 | + _updatersIds[key] = listener; | ||
| 36 | + return () => _updatersIds.remove(key); | ||
| 20 | } | 37 | } | 
| 21 | 38 | ||
| 39 | + void disposeKey(String key) => _updatersIds.remove(key); | ||
| 40 | + | ||
| 22 | @override | 41 | @override | 
| 23 | void onInit() async {} | 42 | void onInit() async {} | 
| 24 | 43 | ||
| @@ -29,6 +48,121 @@ class GetxController extends DisposableInterface { | @@ -29,6 +48,121 @@ class GetxController extends DisposableInterface { | ||
| 29 | void onClose() async {} | 48 | void onClose() async {} | 
| 30 | } | 49 | } | 
| 31 | 50 | ||
| 51 | +// class GetBuilder<T extends GetxController> extends StatefulWidget { | ||
| 52 | +// final Widget Function(T) builder; | ||
| 53 | +// final bool global; | ||
| 54 | +// final String id; | ||
| 55 | +// final String tag; | ||
| 56 | +// final bool autoRemove; | ||
| 57 | +// final bool assignId; | ||
| 58 | +// final void Function(State state) initState, dispose, didChangeDependencies; | ||
| 59 | +// final void Function(GetBuilder oldWidget, State state) didUpdateWidget; | ||
| 60 | +// final T init; | ||
| 61 | +// const GetBuilder({ | ||
| 62 | +// Key key, | ||
| 63 | +// this.init, | ||
| 64 | +// this.global = true, | ||
| 65 | +// @required this.builder, | ||
| 66 | +// this.autoRemove = true, | ||
| 67 | +// this.assignId = false, | ||
| 68 | +// this.initState, | ||
| 69 | +// this.tag, | ||
| 70 | +// this.dispose, | ||
| 71 | +// this.id, | ||
| 72 | +// this.didChangeDependencies, | ||
| 73 | +// this.didUpdateWidget, | ||
| 74 | +// }) : assert(builder != null), | ||
| 75 | +// super(key: key); | ||
| 76 | +// @override | ||
| 77 | +// _GetBuilderState<T> createState() => _GetBuilderState<T>(); | ||
| 78 | +// } | ||
| 79 | + | ||
| 80 | +// class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
| 81 | +// GetxController controller; | ||
| 82 | +// bool isCreator = false; | ||
| 83 | +// @override | ||
| 84 | +// void initState() { | ||
| 85 | +// super.initState(); | ||
| 86 | + | ||
| 87 | +// if (widget.initState != null) widget.initState(this); | ||
| 88 | +// if (widget.global) { | ||
| 89 | +// final isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); | ||
| 90 | +// final isRegistred = GetInstance().isRegistred<T>(tag: widget.tag); | ||
| 91 | + | ||
| 92 | +// if (isPrepared) { | ||
| 93 | +// if (GetConfig.smartManagement != SmartManagement.keepFactory) { | ||
| 94 | +// isCreator = true; | ||
| 95 | +// } | ||
| 96 | +// controller = GetInstance().find<T>(tag: widget.tag); | ||
| 97 | +// } else if (isRegistred) { | ||
| 98 | +// controller = GetInstance().find<T>(tag: widget.tag); | ||
| 99 | +// isCreator = false; | ||
| 100 | +// } else { | ||
| 101 | +// controller = widget.init; | ||
| 102 | +// isCreator = true; | ||
| 103 | +// GetInstance().put<T>(controller, tag: widget.tag); | ||
| 104 | +// } | ||
| 105 | +// } else { | ||
| 106 | +// controller = widget.init; | ||
| 107 | +// isCreator = true; | ||
| 108 | +// controller?.onStart(); | ||
| 109 | +// } | ||
| 110 | + | ||
| 111 | +// if (widget.global && | ||
| 112 | +// GetConfig.smartManagement == SmartManagement.onlyBuilder) { | ||
| 113 | +// controller?.onStart(); | ||
| 114 | +// } | ||
| 115 | +// (widget.id == null) | ||
| 116 | +// ? controller.addListener(setState) | ||
| 117 | +// : controller.addListenerId(widget.id, setState); | ||
| 118 | +// } | ||
| 119 | + | ||
| 120 | +// @override | ||
| 121 | +// void dispose() { | ||
| 122 | +// super.dispose(); | ||
| 123 | +// if (widget.dispose != null) widget.dispose(this); | ||
| 124 | +// if (isCreator || widget.assignId) { | ||
| 125 | +// if (widget.autoRemove && GetInstance().isRegistred<T>(tag: widget.tag)) { | ||
| 126 | +// (widget.id == null) | ||
| 127 | +// ? controller.removeListener(setState) | ||
| 128 | +// : controller.removeListenerId(widget.id); | ||
| 129 | +// GetInstance().delete<T>(tag: widget.tag); | ||
| 130 | +// } | ||
| 131 | +// } else { | ||
| 132 | +// (widget.id == null) | ||
| 133 | +// ? controller.removeListener(setState) | ||
| 134 | +// : controller.removeListenerId(widget.id); | ||
| 135 | +// } | ||
| 136 | +// } | ||
| 137 | + | ||
| 138 | +// @override | ||
| 139 | +// void didChangeDependencies() { | ||
| 140 | +// super.didChangeDependencies(); | ||
| 141 | +// if (widget.didChangeDependencies != null) { | ||
| 142 | +// widget.didChangeDependencies(this); | ||
| 143 | +// } | ||
| 144 | +// } | ||
| 145 | + | ||
| 146 | +// @override | ||
| 147 | +// void didUpdateWidget(GetBuilder oldWidget) { | ||
| 148 | +// super.didUpdateWidget(oldWidget as GetBuilder<T>); | ||
| 149 | +// if (widget.didUpdateWidget != null) widget.didUpdateWidget(oldWidget, this); | ||
| 150 | +// } | ||
| 151 | + | ||
| 152 | +// @override | ||
| 153 | +// Widget build(BuildContext context) { | ||
| 154 | +// return widget.builder(controller); | ||
| 155 | +// } | ||
| 156 | +// } | ||
| 157 | + | ||
| 158 | +// class Updater { | ||
| 159 | +// final StateSetter updater; | ||
| 160 | +// final String id; | ||
| 161 | +// const Updater({this.updater, this.id}); | ||
| 162 | +// } | ||
| 163 | + | ||
| 164 | +// typedef UpdaterBuilder = Updater Function(); | ||
| 165 | + | ||
| 32 | class GetBuilder<T extends GetxController> extends StatefulWidget { | 166 | class GetBuilder<T extends GetxController> extends StatefulWidget { | 
| 33 | final Widget Function(T) builder; | 167 | final Widget Function(T) builder; | 
| 34 | final bool global; | 168 | final bool global; | 
| @@ -59,12 +193,15 @@ class GetBuilder<T extends GetxController> extends StatefulWidget { | @@ -59,12 +193,15 @@ class GetBuilder<T extends GetxController> extends StatefulWidget { | ||
| 59 | } | 193 | } | 
| 60 | 194 | ||
| 61 | class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | 195 | class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | 
| 62 | - T controller; | ||
| 63 | - UpdaterBuilder real; | 196 | + GetxController controller; | 
| 64 | bool isCreator = false; | 197 | bool isCreator = false; | 
| 198 | + final HashSet<Disposer> disposers = HashSet<Disposer>(); | ||
| 199 | + Disposer remove; | ||
| 200 | + | ||
| 65 | @override | 201 | @override | 
| 66 | void initState() { | 202 | void initState() { | 
| 67 | super.initState(); | 203 | super.initState(); | 
| 204 | + | ||
| 68 | if (widget.initState != null) widget.initState(this); | 205 | if (widget.initState != null) widget.initState(this); | 
| 69 | if (widget.global) { | 206 | if (widget.global) { | 
| 70 | final isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); | 207 | final isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); | 
| @@ -75,25 +212,17 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | @@ -75,25 +212,17 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
| 75 | isCreator = true; | 212 | isCreator = true; | 
| 76 | } | 213 | } | 
| 77 | controller = GetInstance().find<T>(tag: widget.tag); | 214 | controller = GetInstance().find<T>(tag: widget.tag); | 
| 78 | - real = () => Updater(updater: setState, id: widget.id); | ||
| 79 | - controller._updaters.add(real); | ||
| 80 | } else if (isRegistred) { | 215 | } else if (isRegistred) { | 
| 81 | controller = GetInstance().find<T>(tag: widget.tag); | 216 | controller = GetInstance().find<T>(tag: widget.tag); | 
| 82 | isCreator = false; | 217 | isCreator = false; | 
| 83 | - real = () => Updater(updater: setState, id: widget.id); | ||
| 84 | - controller._updaters.add(real); | ||
| 85 | } else { | 218 | } else { | 
| 86 | controller = widget.init; | 219 | controller = widget.init; | 
| 87 | isCreator = true; | 220 | isCreator = true; | 
| 88 | - real = () => Updater(updater: setState, id: widget.id); | ||
| 89 | - controller._updaters.add(real); | ||
| 90 | GetInstance().put<T>(controller, tag: widget.tag); | 221 | GetInstance().put<T>(controller, tag: widget.tag); | 
| 91 | } | 222 | } | 
| 92 | } else { | 223 | } else { | 
| 93 | controller = widget.init; | 224 | controller = widget.init; | 
| 94 | isCreator = true; | 225 | isCreator = true; | 
| 95 | - real = () => Updater(updater: setState, id: widget.id); | ||
| 96 | - controller._updaters.add(real); | ||
| 97 | controller?.onStart(); | 226 | controller?.onStart(); | 
| 98 | } | 227 | } | 
| 99 | 228 | ||
| @@ -101,6 +230,9 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | @@ -101,6 +230,9 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
| 101 | GetConfig.smartManagement == SmartManagement.onlyBuilder) { | 230 | GetConfig.smartManagement == SmartManagement.onlyBuilder) { | 
| 102 | controller?.onStart(); | 231 | controller?.onStart(); | 
| 103 | } | 232 | } | 
| 233 | + remove = (widget.id == null) | ||
| 234 | + ? controller?.addListener(setState) | ||
| 235 | + : controller?.addListenerId(widget.id, setState); | ||
| 104 | } | 236 | } | 
| 105 | 237 | ||
| 106 | @override | 238 | @override | 
| @@ -109,12 +241,17 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | @@ -109,12 +241,17 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
| 109 | if (widget.dispose != null) widget.dispose(this); | 241 | if (widget.dispose != null) widget.dispose(this); | 
| 110 | if (isCreator || widget.assignId) { | 242 | if (isCreator || widget.assignId) { | 
| 111 | if (widget.autoRemove && GetInstance().isRegistred<T>(tag: widget.tag)) { | 243 | if (widget.autoRemove && GetInstance().isRegistred<T>(tag: widget.tag)) { | 
| 112 | - controller._updaters.remove(real); | 244 | + if (remove != null) remove(); | 
| 245 | + | ||
| 113 | GetInstance().delete<T>(tag: widget.tag); | 246 | GetInstance().delete<T>(tag: widget.tag); | 
| 114 | } | 247 | } | 
| 115 | } else { | 248 | } else { | 
| 116 | - controller._updaters.remove(real); | 249 | + if (remove != null) remove(); | 
| 117 | } | 250 | } | 
| 251 | + | ||
| 252 | + disposers.forEach((element) { | ||
| 253 | + element(); | ||
| 254 | + }); | ||
| 118 | } | 255 | } | 
| 119 | 256 | ||
| 120 | @override | 257 | @override | 
| @@ -131,16 +268,73 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | @@ -131,16 +268,73 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
| 131 | if (widget.didUpdateWidget != null) widget.didUpdateWidget(oldWidget, this); | 268 | if (widget.didUpdateWidget != null) widget.didUpdateWidget(oldWidget, this); | 
| 132 | } | 269 | } | 
| 133 | 270 | ||
| 271 | + Widget get notifyChilds { | ||
| 272 | + final old = Value._remove; | ||
| 273 | + Value._remove = disposers; | ||
| 274 | + final observer = Value._setter; | ||
| 275 | + Value._setter = setState; | ||
| 276 | + final result = widget.builder(controller); | ||
| 277 | + Value._setter = observer; | ||
| 278 | + Value._remove = old; | ||
| 279 | + return result; | ||
| 280 | + } | ||
| 281 | + | ||
| 134 | @override | 282 | @override | 
| 135 | - Widget build(BuildContext context) { | ||
| 136 | - return widget.builder(controller); | 283 | + Widget build(BuildContext context) => notifyChilds; | 
| 284 | +} | ||
| 285 | + | ||
| 286 | +class Value<T> extends GetxController { | ||
| 287 | + Value([this._value]); | ||
| 288 | + T _value; | ||
| 289 | + | ||
| 290 | + T get value { | ||
| 291 | + if (_setter != null) { | ||
| 292 | + if (!_updaters.contains(_setter)) { | ||
| 293 | + final add = addListener(_setter); | ||
| 294 | + _remove.add(add); | ||
| 295 | + } | ||
| 296 | + } | ||
| 297 | + return _value; | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + static StateSetter _setter; | ||
| 301 | + | ||
| 302 | + static HashSet<Disposer> _remove; | ||
| 303 | + | ||
| 304 | + set value(T newValue) { | ||
| 305 | + if (_value == newValue) return; | ||
| 306 | + _value = newValue; | ||
| 307 | + update(); | ||
| 137 | } | 308 | } | 
| 138 | } | 309 | } | 
| 139 | 310 | ||
| 140 | -class Updater { | ||
| 141 | - final StateSetter updater; | ||
| 142 | - final String id; | ||
| 143 | - const Updater({this.updater, this.id}); | 311 | +class SimpleBuilder extends StatefulWidget { | 
| 312 | + final Widget Function(BuildContext) builder; | ||
| 313 | + const SimpleBuilder({Key key, @required this.builder}) | ||
| 314 | + : assert(builder != null), | ||
| 315 | + super(key: key); | ||
| 316 | + @override | ||
| 317 | + _SimpleBuilderState createState() => _SimpleBuilderState(); | ||
| 144 | } | 318 | } | 
| 145 | 319 | ||
| 146 | -typedef UpdaterBuilder = Updater Function(); | 320 | +class _SimpleBuilderState extends State<SimpleBuilder> { | 
| 321 | + final HashSet<Disposer> disposers = HashSet<Disposer>(); | ||
| 322 | + | ||
| 323 | + @override | ||
| 324 | + void dispose() { | ||
| 325 | + super.dispose(); | ||
| 326 | + disposers.forEach((element) => element()); | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + @override | ||
| 330 | + Widget build(BuildContext context) { | ||
| 331 | + HashSet<Disposer> old = Value._remove; | ||
| 332 | + Value._remove = disposers; | ||
| 333 | + StateSetter observer = Value._setter; | ||
| 334 | + Value._setter = setState; | ||
| 335 | + Widget result = widget.builder(context); | ||
| 336 | + Value._remove = old; | ||
| 337 | + Value._setter = observer; | ||
| 338 | + return result; | ||
| 339 | + } | ||
| 340 | +} | 
lib/state_manager.dart
0 → 100644
| 1 | +export 'src/state_manager/simple/get_state.dart'; | ||
| 2 | +export 'src/state_manager/simple/immutable_state.dart'; | ||
| 3 | +export 'src/state_manager/simple/get_view.dart'; | ||
| 4 | +export 'src/state_manager/simple/mixin_state.dart'; | ||
| 5 | +export 'src/state_manager/rx/rx_interface.dart'; | ||
| 6 | +export 'src/state_manager/rx/rx_impl.dart'; | ||
| 7 | +export 'src/state_manager/rx/rx_event.dart'; | ||
| 8 | +export 'src/state_manager/rx/rx_obx.dart'; | ||
| 9 | +export 'src/state_manager/rx/rx_getbuilder.dart'; | 
lib/utils.dart
0 → 100644
| @@ -7,7 +7,7 @@ packages: | @@ -7,7 +7,7 @@ packages: | ||
| 7 | name: async | 7 | name: async | 
| 8 | url: "https://pub.dartlang.org" | 8 | url: "https://pub.dartlang.org" | 
| 9 | source: hosted | 9 | source: hosted | 
| 10 | - version: "2.4.1" | 10 | + version: "2.4.2" | 
| 11 | boolean_selector: | 11 | boolean_selector: | 
| 12 | dependency: transitive | 12 | dependency: transitive | 
| 13 | description: | 13 | description: | 
| @@ -21,7 +21,7 @@ packages: | @@ -21,7 +21,7 @@ packages: | ||
| 21 | name: characters | 21 | name: characters | 
| 22 | url: "https://pub.dartlang.org" | 22 | url: "https://pub.dartlang.org" | 
| 23 | source: hosted | 23 | source: hosted | 
| 24 | - version: "1.0.0" | 24 | + version: "1.1.0-nullsafety" | 
| 25 | charcode: | 25 | charcode: | 
| 26 | dependency: transitive | 26 | dependency: transitive | 
| 27 | description: | 27 | description: | 
| @@ -42,7 +42,7 @@ packages: | @@ -42,7 +42,7 @@ packages: | ||
| 42 | name: collection | 42 | name: collection | 
| 43 | url: "https://pub.dartlang.org" | 43 | url: "https://pub.dartlang.org" | 
| 44 | source: hosted | 44 | source: hosted | 
| 45 | - version: "1.14.13" | 45 | + version: "1.15.0-nullsafety" | 
| 46 | fake_async: | 46 | fake_async: | 
| 47 | dependency: transitive | 47 | dependency: transitive | 
| 48 | description: | 48 | description: | 
| @@ -73,7 +73,7 @@ packages: | @@ -73,7 +73,7 @@ packages: | ||
| 73 | name: meta | 73 | name: meta | 
| 74 | url: "https://pub.dartlang.org" | 74 | url: "https://pub.dartlang.org" | 
| 75 | source: hosted | 75 | source: hosted | 
| 76 | - version: "1.1.8" | 76 | + version: "1.3.0-nullsafety" | 
| 77 | path: | 77 | path: | 
| 78 | dependency: transitive | 78 | dependency: transitive | 
| 79 | description: | 79 | description: | 
| @@ -99,7 +99,7 @@ packages: | @@ -99,7 +99,7 @@ packages: | ||
| 99 | name: stack_trace | 99 | name: stack_trace | 
| 100 | url: "https://pub.dartlang.org" | 100 | url: "https://pub.dartlang.org" | 
| 101 | source: hosted | 101 | source: hosted | 
| 102 | - version: "1.9.3" | 102 | + version: "1.9.5" | 
| 103 | stream_channel: | 103 | stream_channel: | 
| 104 | dependency: transitive | 104 | dependency: transitive | 
| 105 | description: | 105 | description: | 
| @@ -134,13 +134,13 @@ packages: | @@ -134,13 +134,13 @@ packages: | ||
| 134 | name: typed_data | 134 | name: typed_data | 
| 135 | url: "https://pub.dartlang.org" | 135 | url: "https://pub.dartlang.org" | 
| 136 | source: hosted | 136 | source: hosted | 
| 137 | - version: "1.2.0" | 137 | + version: "1.3.0-nullsafety" | 
| 138 | vector_math: | 138 | vector_math: | 
| 139 | dependency: transitive | 139 | dependency: transitive | 
| 140 | description: | 140 | description: | 
| 141 | name: vector_math | 141 | name: vector_math | 
| 142 | url: "https://pub.dartlang.org" | 142 | url: "https://pub.dartlang.org" | 
| 143 | source: hosted | 143 | source: hosted | 
| 144 | - version: "2.0.8" | 144 | + version: "2.1.0-nullsafety" | 
| 145 | sdks: | 145 | sdks: | 
| 146 | - dart: ">=2.9.0-14.0.dev <3.0.0" | 146 | + dart: ">=2.9.0-18.0 <2.9.0" | 
| 1 | name: get | 1 | name: get | 
| 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX. | 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX. | 
| 3 | -version: 3.4.1 | 3 | +version: 3.4.3 | 
| 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