Showing
10 changed files
with
78 additions
and
274 deletions
@@ -667,7 +667,7 @@ Obviously, if someone wants to contribute to the project and create a code gener | @@ -667,7 +667,7 @@ Obviously, if someone wants to contribute to the project and create a code gener | ||
667 | Typing in Get using Bindings is unnecessary. you can use the Obx widget instead of GetX which only receives the anonymous function that creates a widget. | 667 | Typing in Get using Bindings is unnecessary. you can use the Obx widget instead of GetX which only receives the anonymous function that creates a widget. |
668 | Obviously, if you don't use a type, you will need to have an instance of your controller to use the variables, or use `Get.find<Controller>()` .value or Controller.to.value to retrieve the value. | 668 | Obviously, if you don't use a type, you will need to have an instance of your controller to use the variables, or use `Get.find<Controller>()` .value or Controller.to.value to retrieve the value. |
669 | 669 | ||
670 | -### GetX vs GetBuilder vs Obx MixinBuilder | 670 | +### GetX vs GetBuilder vs Obx vs MixinBuilder |
671 | In a decade working with programming I was able to learn some valuable lessons. | 671 | In a decade working with programming I was able to learn some valuable lessons. |
672 | My first contact with reactive programming was so "wow, this is incredible" and in fact reactive programming is incredible. | 672 | My first contact with reactive programming was so "wow, this is incredible" and in fact reactive programming is incredible. |
673 | However, it is not suitable for all situations. Often all you need is to change the state of 2 or 3 widgets at the same time, or an ephemeral change of state, in which case reactive programming is not bad, but it is not appropriate. | 673 | However, it is not suitable for all situations. Often all you need is to change the state of 2 or 3 widgets at the same time, or an ephemeral change of state, in which case reactive programming is not bad, but it is not appropriate. |
@@ -764,6 +764,23 @@ Get.to(Home(), binding: HomeBinding()); | @@ -764,6 +764,23 @@ Get.to(Home(), binding: HomeBinding()); | ||
764 | 764 | ||
765 | There, you don't have to worry about memory management of your application anymore, Get will do it for you. | 765 | There, you don't have to worry about memory management of your application anymore, Get will do it for you. |
766 | 766 | ||
767 | +The Binding class is called when a route is called, you can create an "initialBinding in your GetMaterialApp to insert all the dependencies that will be created. | ||
768 | +```dart | ||
769 | +GetMaterialApp( | ||
770 | + initialBinding: SampleBind(), | ||
771 | + home: Home(); | ||
772 | +); | ||
773 | +``` | ||
774 | + | ||
775 | +If you want to use your initializations in one place, you can use SmartManagement.keepfactory to allow this, and although using keepfactory should be the exception, as it is the softest SmartManagement out there. | ||
776 | + | ||
777 | +I always prefer the standard SmartManagement (full). It can be annoying at times, and eliminate something you don't want, as it has refined controls that remove memory dependency even if there is a flaw, and a widget is not arranged properly. It is safe enough with StatelessWidget, since even if there is no page available, it will still remove the controller from memory. But there are some use cases, which this restriction can be bothersome. For these situations you can use SmartManagement.onlyBuilders, which will depend on the effective removal of widgets that use the controller from the tree to remove the controller. | ||
778 | + | ||
779 | +- NOTE: DO NOT USE SmartManagement.keepFactory if you are using multiple Bindings. It was designed to be used without Bindings, or with a single Binding linked in the GetBaterialApp's initialBinding. | ||
780 | + | ||
781 | +- NOTE2: Using Bindings is completely optional, you can use Get.put() and Get.find() on classes that use a given controller without any problem. | ||
782 | +However, if you work with Services or any other abstraction, I recommend using Bindings for a larger organization. | ||
783 | + | ||
767 | ## Workers: | 784 | ## Workers: |
768 | Workers will assist you, triggering specific callbacks when an event occurs. | 785 | Workers will assist you, triggering specific callbacks when an event occurs. |
769 | 786 | ||
@@ -1062,7 +1079,7 @@ You don't need the context, and you will find your navigation stack by Id. | @@ -1062,7 +1079,7 @@ You don't need the context, and you will find your navigation stack by Id. | ||
1062 | See how simple it is: | 1079 | See how simple it is: |
1063 | ```dart | 1080 | ```dart |
1064 | Navigator( | 1081 | Navigator( |
1065 | - key: nestedKey(1), // create a key by index | 1082 | + key: Get.nestedKey(1), // create a key by index |
1066 | initialRoute: '/', | 1083 | initialRoute: '/', |
1067 | onGenerateRoute: (settings) { | 1084 | onGenerateRoute: (settings) { |
1068 | if (settings.name == '/') { | 1085 | if (settings.name == '/') { |
@@ -1146,7 +1163,7 @@ Get.offNamedUntil() // go to next named route and remove all the previous routes | @@ -1146,7 +1163,7 @@ Get.offNamedUntil() // go to next named route and remove all the previous routes | ||
1146 | 1163 | ||
1147 | GetPlatform.isAndroid/isIOS/isWeb... //(This method is completely compatible with FlutterWeb, unlike the framework. "Platform.isAndroid") | 1164 | GetPlatform.isAndroid/isIOS/isWeb... //(This method is completely compatible with FlutterWeb, unlike the framework. "Platform.isAndroid") |
1148 | 1165 | ||
1149 | -Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height | 1166 | +Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height, but they are immutable. If you need a changeable height/width (like browser windows that can be scaled) you will need to use context.height and context.width |
1150 | 1167 | ||
1151 | Get.context // Gives the context of the screen in the foreground anywhere in your code. | 1168 | Get.context // Gives the context of the screen in the foreground anywhere in your code. |
1152 | 1169 |
@@ -755,7 +755,7 @@ class Get { | @@ -755,7 +755,7 @@ class Get { | ||
755 | bool callInit = false; | 755 | bool callInit = false; |
756 | if (Get.isRegistred<S>(tag: tag)) { | 756 | if (Get.isRegistred<S>(tag: tag)) { |
757 | if (!isDependencyInit<S>() && | 757 | if (!isDependencyInit<S>() && |
758 | - Get().smartManagement == SmartManagement.full) { | 758 | + Get().smartManagement != SmartManagement.onlyBuilder) { |
759 | Get().registerRouteInstance<S>(tag: tag); | 759 | Get().registerRouteInstance<S>(tag: tag); |
760 | callInit = true; | 760 | callInit = true; |
761 | } | 761 | } |
@@ -781,7 +781,7 @@ class Get { | @@ -781,7 +781,7 @@ class Get { | ||
781 | S _value = Get.put<S>(Get()._factory[key].call() as S); | 781 | S _value = Get.put<S>(Get()._factory[key].call() as S); |
782 | 782 | ||
783 | if (!isDependencyInit<S>() && | 783 | if (!isDependencyInit<S>() && |
784 | - Get().smartManagement == SmartManagement.full) { | 784 | + Get().smartManagement != SmartManagement.onlyBuilder) { |
785 | Get().registerRouteInstance<S>(tag: tag); | 785 | Get().registerRouteInstance<S>(tag: tag); |
786 | callInit = true; | 786 | callInit = true; |
787 | } | 787 | } |
@@ -902,13 +902,6 @@ class Get { | @@ -902,13 +902,6 @@ class Get { | ||
902 | /// give current arguments | 902 | /// give current arguments |
903 | static Map<String, String> get parameters => Get()._parameters; | 903 | static Map<String, String> get parameters => Get()._parameters; |
904 | 904 | ||
905 | - /// interface to GetX | ||
906 | - RxInterface _obs; | ||
907 | - | ||
908 | - static RxInterface get obs => Get()._obs; | ||
909 | - | ||
910 | - static set obs(RxInterface observer) => Get()._obs = observer; | ||
911 | - | ||
912 | /// give name from current route | 905 | /// give name from current route |
913 | static get currentRoute => Get()._routing.current; | 906 | static get currentRoute => Get()._routing.current; |
914 | 907 | ||
@@ -1005,6 +998,8 @@ class _FcBuilder<S> { | @@ -1005,6 +998,8 @@ class _FcBuilder<S> { | ||
1005 | } | 998 | } |
1006 | } | 999 | } |
1007 | 1000 | ||
1001 | + | ||
1002 | + | ||
1008 | typedef _FcBuilderFunc<S> = S Function(); | 1003 | typedef _FcBuilderFunc<S> = S Function(); |
1009 | 1004 | ||
1010 | typedef _FcBuilderFuncAsync<S> = Future<S> Function(); | 1005 | typedef _FcBuilderFuncAsync<S> = Future<S> Function(); |
@@ -94,7 +94,7 @@ class GetObserver extends NavigatorObserver { | @@ -94,7 +94,7 @@ class GetObserver extends NavigatorObserver { | ||
94 | if (Get.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}"); | 94 | if (Get.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}"); |
95 | } | 95 | } |
96 | 96 | ||
97 | - if (Get().smartManagement == SmartManagement.full) { | 97 | + if (Get().smartManagement != SmartManagement.onlyBuilder) { |
98 | Get().removeDependencyByRoute("${route?.settings?.name}"); | 98 | Get().removeDependencyByRoute("${route?.settings?.name}"); |
99 | } | 99 | } |
100 | 100 |
@@ -43,7 +43,9 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -43,7 +43,9 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
43 | bool isRegistred = Get.isRegistred<T>(); | 43 | bool isRegistred = Get.isRegistred<T>(); |
44 | if (widget.global) { | 44 | if (widget.global) { |
45 | if (isPrepared) { | 45 | if (isPrepared) { |
46 | - isCreator = true; | 46 | + if (Get().smartManagement != SmartManagement.keepFactory) { |
47 | + isCreator = true; | ||
48 | + } | ||
47 | controller = Get.find<T>(); | 49 | controller = Get.find<T>(); |
48 | } else if (isRegistred) { | 50 | } else if (isRegistred) { |
49 | controller = Get.find<T>(); | 51 | controller = Get.find<T>(); |
@@ -62,26 +64,19 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -62,26 +64,19 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
62 | if (isCreator && Get().smartManagement == SmartManagement.onlyBuilder) { | 64 | if (isCreator && Get().smartManagement == SmartManagement.onlyBuilder) { |
63 | controller?.onInit(); | 65 | controller?.onInit(); |
64 | } | 66 | } |
65 | - | ||
66 | - _observer.subject.stream.listen((data) { | ||
67 | - setState(() {}); | ||
68 | - }); | 67 | + _observer.subject.stream.listen((data) => setState(() {})); |
69 | super.initState(); | 68 | super.initState(); |
70 | } | 69 | } |
71 | 70 | ||
72 | @override | 71 | @override |
73 | void dispose() { | 72 | void dispose() { |
74 | if (widget.dispose != null) widget.dispose(this); | 73 | if (widget.dispose != null) widget.dispose(this); |
75 | - | ||
76 | if (isCreator || widget.assignId) { | 74 | if (isCreator || widget.assignId) { |
77 | if (widget.autoRemove && Get.isRegistred<T>()) { | 75 | if (widget.autoRemove && Get.isRegistred<T>()) { |
78 | - // controller.onClose(); | ||
79 | Get.delete<T>(); | 76 | Get.delete<T>(); |
80 | } | 77 | } |
81 | - // } else { | ||
82 | - // controller.onClose(); | ||
83 | } | 78 | } |
84 | - // controller.onClose(); | 79 | + |
85 | _observer.close(); | 80 | _observer.close(); |
86 | controller = null; | 81 | controller = null; |
87 | isCreator = null; | 82 | isCreator = null; |
@@ -90,10 +85,10 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -90,10 +85,10 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
90 | 85 | ||
91 | @override | 86 | @override |
92 | Widget build(BuildContext context) { | 87 | Widget build(BuildContext context) { |
93 | - final observer = Get.obs; | ||
94 | - Get.obs = this._observer; | 88 | + final observer = getObs; |
89 | + getObs = this._observer; | ||
95 | final result = widget.builder(controller); | 90 | final result = widget.builder(controller); |
96 | - Get.obs = observer; | 91 | + getObs = observer; |
97 | return result; | 92 | return result; |
98 | } | 93 | } |
99 | } | 94 | } |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | -import 'package:get/src/get_main.dart'; | ||
3 | import 'rx_callbacks.dart'; | 2 | import 'rx_callbacks.dart'; |
4 | import 'rx_interface.dart'; | 3 | import 'rx_interface.dart'; |
5 | import 'rx_model.dart'; | 4 | import 'rx_model.dart'; |
@@ -11,8 +10,8 @@ class _RxImpl<T> implements RxInterface<T> { | @@ -11,8 +10,8 @@ class _RxImpl<T> implements RxInterface<T> { | ||
11 | 10 | ||
12 | T _value; | 11 | T _value; |
13 | T get v { | 12 | T get v { |
14 | - if (Get.obs != null) { | ||
15 | - Get.obs.addListener(subject.stream); | 13 | + if (getObs != null) { |
14 | + getObs.addListener(subject.stream); | ||
16 | } | 15 | } |
17 | return _value; | 16 | return _value; |
18 | } | 17 | } |
@@ -111,16 +110,8 @@ class MapX<Map> extends _RxImpl<Map> { | @@ -111,16 +110,8 @@ class MapX<Map> extends _RxImpl<Map> { | ||
111 | } | 110 | } |
112 | } | 111 | } |
113 | 112 | ||
114 | -// class ListX<List> extends _RxImpl<List> { | ||
115 | -// ListX([List initial]) { | ||
116 | -// _value = initial; | ||
117 | -// _onChange = subject.stream.asBroadcastStream(); | ||
118 | -// } | ||
119 | -// } | ||
120 | - | 113 | +/// Create a list similar to `List<T>` |
121 | class ListX<E> extends Iterable<E> implements RxInterface<E> { | 114 | class ListX<E> extends Iterable<E> implements RxInterface<E> { |
122 | - /// Create a list similar to `List<T>` | ||
123 | - | ||
124 | ListX([List<E> initial]) { | 115 | ListX([List<E> initial]) { |
125 | _list = initial; | 116 | _list = initial; |
126 | _onChange = subject.stream.asBroadcastStream(); | 117 | _onChange = subject.stream.asBroadcastStream(); |
@@ -159,7 +150,7 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -159,7 +150,7 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
159 | 150 | ||
160 | operator []=(int index, E val) { | 151 | operator []=(int index, E val) { |
161 | _list[index] = val; | 152 | _list[index] = val; |
162 | - subject.add(Change<E>.set($new: val, item: val, pos: index)); | 153 | + subject.add(Change<E>.set($new: val, pos: index)); |
163 | } | 154 | } |
164 | 155 | ||
165 | E operator [](int index) { | 156 | E operator [](int index) { |
@@ -168,13 +159,12 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -168,13 +159,12 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
168 | 159 | ||
169 | void add(E item) { | 160 | void add(E item) { |
170 | _list.add(item); | 161 | _list.add(item); |
171 | - subject | ||
172 | - .add(Change<E>.insert($new: item, item: item, pos: _list.length - 1)); | 162 | + subject.add(Change<E>.insert($new: item, pos: _list.length - 1)); |
173 | } | 163 | } |
174 | 164 | ||
175 | void addAll(List<E> item) { | 165 | void addAll(List<E> item) { |
176 | _list.addAll(item); | 166 | _list.addAll(item); |
177 | - subject.add(Change<E>.insert(item: _list, pos: _list.length - 1)); | 167 | + subject.add(Change<E>.insert($new: _list, pos: _list.length - 1)); |
178 | } | 168 | } |
179 | 169 | ||
180 | /// Adds only if [item] is not null. | 170 | /// Adds only if [item] is not null. |
@@ -189,12 +179,12 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -189,12 +179,12 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
189 | 179 | ||
190 | void insert(int index, E item) { | 180 | void insert(int index, E item) { |
191 | _list.insert(index, item); | 181 | _list.insert(index, item); |
192 | - subject.add(Change<E>.insert(item: item, pos: index)); | 182 | + subject.add(Change<E>.insert($new: item, pos: index)); |
193 | } | 183 | } |
194 | 184 | ||
195 | void insertAll(int index, Iterable<E> iterable) { | 185 | void insertAll(int index, Iterable<E> iterable) { |
196 | _list.insertAll(index, iterable); | 186 | _list.insertAll(index, iterable); |
197 | - subject.add(Change<E>.insert(item: iterable.last, pos: index)); | 187 | + subject.add(Change<E>.insert($new: iterable.last, pos: index)); |
198 | } | 188 | } |
199 | 189 | ||
200 | int get length => value.length; | 190 | int get length => value.length; |
@@ -208,32 +198,32 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -208,32 +198,32 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
208 | int pos = _list.indexOf(item); | 198 | int pos = _list.indexOf(item); |
209 | bool hasRemoved = _list.remove(item); | 199 | bool hasRemoved = _list.remove(item); |
210 | if (hasRemoved) { | 200 | if (hasRemoved) { |
211 | - subject.add(Change<E>.remove(item: item, pos: pos)); | 201 | + subject.add(Change<E>.remove($new: item, pos: pos)); |
212 | } | 202 | } |
213 | return hasRemoved; | 203 | return hasRemoved; |
214 | } | 204 | } |
215 | 205 | ||
216 | E removeAt(int index) { | 206 | E removeAt(int index) { |
217 | E item = _list.removeAt(index); | 207 | E item = _list.removeAt(index); |
218 | - subject.add(Change<E>.remove(item: item, pos: index)); | 208 | + subject.add(Change<E>.remove($new: item, pos: index)); |
219 | return item; | 209 | return item; |
220 | } | 210 | } |
221 | 211 | ||
222 | E removeLast() { | 212 | E removeLast() { |
223 | int pos = _list.indexOf(_list.last); | 213 | int pos = _list.indexOf(_list.last); |
224 | E item = _list.removeLast(); | 214 | E item = _list.removeLast(); |
225 | - subject.add(Change<E>.remove(item: item, pos: pos)); | 215 | + subject.add(Change<E>.remove($new: item, pos: pos)); |
226 | return item; | 216 | return item; |
227 | } | 217 | } |
228 | 218 | ||
229 | void removeRange(int start, int end) { | 219 | void removeRange(int start, int end) { |
230 | _list.removeRange(start, end); | 220 | _list.removeRange(start, end); |
231 | - subject.add(Change<E>.remove(item: null, pos: null)); | 221 | + subject.add(Change<E>.remove($new: null, pos: null)); |
232 | } | 222 | } |
233 | 223 | ||
234 | void removeWhere(bool Function(E) test) { | 224 | void removeWhere(bool Function(E) test) { |
235 | _list.removeWhere(test); | 225 | _list.removeWhere(test); |
236 | - subject.add(Change<E>.remove(item: null, pos: null)); | 226 | + subject.add(Change<E>.remove($new: null, pos: null)); |
237 | } | 227 | } |
238 | 228 | ||
239 | void clear() { | 229 | void clear() { |
@@ -287,8 +277,8 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -287,8 +277,8 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
287 | 277 | ||
288 | @override | 278 | @override |
289 | get v { | 279 | get v { |
290 | - if (Get.obs != null) { | ||
291 | - Get.obs.addListener(subject.stream); | 280 | + if (getObs != null) { |
281 | + getObs.addListener(subject.stream); | ||
292 | } | 282 | } |
293 | return _list; | 283 | return _list; |
294 | } | 284 | } |
@@ -298,7 +288,7 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -298,7 +288,7 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
298 | } | 288 | } |
299 | 289 | ||
300 | @override | 290 | @override |
301 | - Stream<E> get stream => onChange.map((c) => c.item); | 291 | + Stream<E> get stream => onChange.map((c) => c.$new); |
302 | 292 | ||
303 | @override | 293 | @override |
304 | void bind(RxInterface<E> reactive) { | 294 | void bind(RxInterface<E> reactive) { |
@@ -329,205 +319,12 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | @@ -329,205 +319,12 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> { | ||
329 | List<E> _list = <E>[]; | 319 | List<E> _list = <E>[]; |
330 | } | 320 | } |
331 | 321 | ||
332 | -// class ListX<E> extends DelegatingList<E> implements List<E>, RxInterface<E> { | ||
333 | -// /// Create a list similar to `List<T>` | ||
334 | -// ListX([int length]) : super(length != null ? List<E>(length) : List<E>()) { | ||
335 | -// _onChange = subject.stream.asBroadcastStream(); | ||
336 | -// } | ||
337 | - | ||
338 | -// ListX.filled(int length, E fill, {bool growable: false}) | ||
339 | -// : super(List<E>.filled(length, fill, growable: growable)) { | ||
340 | -// _onChange = subject.stream.asBroadcastStream(); | ||
341 | -// } | ||
342 | - | ||
343 | -// ListX.from(Iterable<E> items, {bool growable: true}) | ||
344 | -// : super(List<E>.from(items, growable: growable)) { | ||
345 | -// _onChange = subject.stream.asBroadcastStream(); | ||
346 | -// } | ||
347 | - | ||
348 | -// ListX.union(Iterable<E> items, [E item]) : super(items?.toList() ?? <E>[]) { | ||
349 | -// if (item != null) add(item); | ||
350 | -// _onChange = subject.stream.asBroadcastStream(); | ||
351 | -// } | ||
352 | - | ||
353 | -// ListX.of(Iterable<E> items, {bool growable: true}) | ||
354 | -// : super(List<E>.of(items, growable: growable)); | ||
355 | - | ||
356 | -// ListX.generate(int length, E generator(int index), {bool growable: true}) | ||
357 | -// : super(List<E>.generate(length, generator, growable: growable)); | ||
358 | - | ||
359 | -// Map<Stream<Change<E>>, StreamSubscription> _subscriptions = Map(); | ||
360 | - | ||
361 | -// // StreamSubscription _changectl = StreamSubscription(); | ||
362 | - | ||
363 | -// StreamController<Change<E>> _changeCtl = | ||
364 | -// StreamController<Change<E>>.broadcast(); | ||
365 | - | ||
366 | -// @override | ||
367 | -// StreamController<Change<E>> subject = StreamController<Change<E>>.broadcast(); | ||
368 | - | ||
369 | -// /// Adds [item] only if [condition] resolves to true. | ||
370 | -// void addIf(condition, E item) { | ||
371 | -// if (condition is Condition) condition = condition(); | ||
372 | -// if (condition is bool && condition) add(item); | ||
373 | -// } | ||
374 | - | ||
375 | -// /// Adds all [items] only if [condition] resolves to true. | ||
376 | -// void addAllIf(condition, Iterable<E> items) { | ||
377 | -// if (condition is Condition) condition = condition(); | ||
378 | -// if (condition is bool && condition) addAll(items); | ||
379 | -// } | ||
380 | - | ||
381 | -// operator []=(int index, E value) { | ||
382 | -// super[index] = value; | ||
383 | -// if (Get.obs != null) { | ||
384 | -// Get.obs.addListener(subject.stream); | ||
385 | -// } | ||
386 | -// subject.add(Change<E>.set(item: value, pos: index)); | ||
387 | -// } | ||
388 | - | ||
389 | -// void _add(E item) => super.add(item); | ||
390 | - | ||
391 | -// void add(E item) { | ||
392 | -// super.add(item); | ||
393 | -// subject.add(Change<E>.insert(item: item, pos: length - 1)); | ||
394 | -// } | ||
395 | - | ||
396 | -// /// Adds only if [item] is not null. | ||
397 | -// void addNonNull(E item) { | ||
398 | -// if (item != null) add(item); | ||
399 | -// } | ||
400 | - | ||
401 | -// void insert(int index, E item) { | ||
402 | -// super.insert(index, item); | ||
403 | -// subject.add(Change<E>.insert(item: item, pos: index)); | ||
404 | -// } | ||
405 | - | ||
406 | -// bool remove(Object item) { | ||
407 | -// int pos = indexOf(item); | ||
408 | -// bool hasRemoved = super.remove(item); | ||
409 | -// if (hasRemoved) { | ||
410 | -// subject.add(Change<E>.remove(item: item, pos: pos)); | ||
411 | -// } | ||
412 | -// return hasRemoved; | ||
413 | -// } | ||
414 | - | ||
415 | -// void clear() { | ||
416 | -// super.clear(); | ||
417 | -// subject.add(Change<E>.clear()); | ||
418 | -// } | ||
419 | - | ||
420 | -// close() { | ||
421 | -// clear(); | ||
422 | -// _subscriptions.forEach((observable, subscription) { | ||
423 | -// subscription.cancel(); | ||
424 | -// }); | ||
425 | -// _subscriptions.clear(); | ||
426 | -// subject.close(); | ||
427 | -// _changeCtl.close(); | ||
428 | -// } | ||
429 | - | ||
430 | -// /// Replaces all existing items of this list with [item] | ||
431 | -// void assign(E item) { | ||
432 | -// clear(); | ||
433 | -// add(item); | ||
434 | -// } | ||
435 | - | ||
436 | -// /// Replaces all existing items of this list with [items] | ||
437 | -// void assignAll(Iterable<E> items) { | ||
438 | -// clear(); | ||
439 | -// addAll(items); | ||
440 | -// } | ||
441 | - | ||
442 | -// /// A stream of record of changes to this list | ||
443 | -// Stream<Change<E>> get onChange { | ||
444 | -// final now = DateTime.now(); | ||
445 | - | ||
446 | -// _onChange.skipWhile((m) => m.time.isBefore(now)); | ||
447 | -// return _changeCtl.stream.asBroadcastStream(); | ||
448 | -// } | ||
449 | - | ||
450 | -// Stream<Change<E>> _onChange; | ||
451 | - | ||
452 | -// addListener(Stream<Change<E>> rxGetx) { | ||
453 | -// if (_subscriptions.containsKey(rxGetx)) { | ||
454 | -// return; | ||
455 | -// } | ||
456 | -// _subscriptions[rxGetx] = rxGetx.listen((data) { | ||
457 | -// subject.add(data); | ||
458 | -// }); | ||
459 | -// } | ||
460 | - | ||
461 | -// List<E> get value => v as List<E>; | ||
462 | - | ||
463 | -// set value(List<E> va) => assignAll(va); | ||
464 | - | ||
465 | -// @override | ||
466 | -// get v { | ||
467 | -// if (Get.obs != null) { | ||
468 | -// Get.obs.addListener(subject.stream); | ||
469 | -// } | ||
470 | -// return this; | ||
471 | -// } | ||
472 | - | ||
473 | -// set v(E val) { | ||
474 | -// assign(val); | ||
475 | -// } | ||
476 | - | ||
477 | -// @override | ||
478 | -// Stream<E> get stream => onChange.map((c) => c.item); | ||
479 | - | ||
480 | -// @override | ||
481 | -// void bind(RxInterface<E> reactive) { | ||
482 | -// v = reactive.v; | ||
483 | -// reactive.stream.listen((va) => v = va); | ||
484 | -// } | ||
485 | - | ||
486 | -// void bindStream(Stream<E> stream) => stream.listen((va) => v = va); | ||
487 | - | ||
488 | -// @override | ||
489 | -// void bindOrSet(/* T | Stream<T> or Rx<T> */ other) { | ||
490 | -// if (other is RxInterface<E>) { | ||
491 | -// bind(other); | ||
492 | -// } else if (other is Stream<E>) { | ||
493 | -// bindStream(other.cast<E>()); | ||
494 | -// } else { | ||
495 | -// v = other; | ||
496 | -// } | ||
497 | -// } | ||
498 | - | ||
499 | -// @override | ||
500 | -// StreamSubscription<E> listen(ValueCallback<E> callback) => | ||
501 | -// stream.listen(callback); | ||
502 | - | ||
503 | -// @override | ||
504 | -// void setCast(dynamic val) => v = val; | ||
505 | -// } | 322 | +RxInterface getObs; |
506 | 323 | ||
507 | typedef bool Condition(); | 324 | typedef bool Condition(); |
508 | 325 | ||
509 | typedef E ChildrenListComposer<S, E>(S value); | 326 | typedef E ChildrenListComposer<S, E>(S value); |
510 | 327 | ||
511 | -// /// An observable list that is bound to another list [binding] | ||
512 | -// class BindingList<S, E> extends ListX<E> { | ||
513 | -// final ListX<S> binding; | ||
514 | - | ||
515 | -// final ChildrenListComposer<S, E> composer; | ||
516 | - | ||
517 | -// BindingList(this.binding, this.composer) { | ||
518 | -// for (S v in binding) _add(composer(v)); | ||
519 | -// binding.onChange.listen((Change<S> n) { | ||
520 | -// if (n.op == ListChangeOp.add) { | ||
521 | -// insert(n.pos, composer(n.item)); | ||
522 | -// } else if (n.op == ListChangeOp.remove) { | ||
523 | -// removeAt(n.pos); | ||
524 | -// } else if (n.op == ListChangeOp.clear) { | ||
525 | -// clear(); | ||
526 | -// } | ||
527 | -// }); | ||
528 | -// } | ||
529 | -// } | ||
530 | - | ||
531 | class BoolX<bool> extends _RxImpl<bool> { | 328 | class BoolX<bool> extends _RxImpl<bool> { |
532 | BoolX([bool initial]) { | 329 | BoolX([bool initial]) { |
533 | _value = initial; | 330 | _value = initial; |
@@ -3,9 +3,9 @@ class Change<T> { | @@ -3,9 +3,9 @@ class Change<T> { | ||
3 | final T $old; | 3 | final T $old; |
4 | 4 | ||
5 | /// Value after change | 5 | /// Value after change |
6 | - final T $new; | 6 | + final $new; |
7 | + | ||
7 | 8 | ||
8 | - final item; | ||
9 | 9 | ||
10 | final ListChangeOp op; | 10 | final ListChangeOp op; |
11 | 11 | ||
@@ -17,7 +17,7 @@ class Change<T> { | @@ -17,7 +17,7 @@ class Change<T> { | ||
17 | {this.$new, | 17 | {this.$new, |
18 | this.$old, | 18 | this.$old, |
19 | this.batch, | 19 | this.batch, |
20 | - this.item, | 20 | + |
21 | this.op, | 21 | this.op, |
22 | this.pos, | 22 | this.pos, |
23 | DateTime time}) | 23 | DateTime time}) |
@@ -25,24 +25,24 @@ class Change<T> { | @@ -25,24 +25,24 @@ class Change<T> { | ||
25 | String toString() => 'Change(new: ${$new}, old: ${$old})'; | 25 | String toString() => 'Change(new: ${$new}, old: ${$old})'; |
26 | 26 | ||
27 | Change.insert( | 27 | Change.insert( |
28 | - {this.$new, this.$old, this.batch, this.item, this.pos, DateTime time}) | 28 | + {this.$new, this.$old, this.batch, this.pos, DateTime time}) |
29 | : op = ListChangeOp.add, | 29 | : op = ListChangeOp.add, |
30 | time = time ?? new DateTime.now(); | 30 | time = time ?? new DateTime.now(); |
31 | 31 | ||
32 | Change.set( | 32 | Change.set( |
33 | - {this.$new, this.$old, this.batch, this.item, this.pos, DateTime time}) | 33 | + {this.$new, this.$old, this.batch, this.pos, DateTime time}) |
34 | : op = ListChangeOp.set, | 34 | : op = ListChangeOp.set, |
35 | time = time ?? new DateTime.now(); | 35 | time = time ?? new DateTime.now(); |
36 | 36 | ||
37 | Change.remove( | 37 | Change.remove( |
38 | - {this.$new, this.$old, this.batch, this.item, this.pos, DateTime time}) | 38 | + {this.$new, this.$old, this.batch, this.pos, DateTime time}) |
39 | : op = ListChangeOp.remove, | 39 | : op = ListChangeOp.remove, |
40 | time = time ?? new DateTime.now(); | 40 | time = time ?? new DateTime.now(); |
41 | 41 | ||
42 | Change.clear({this.$new, this.$old, this.batch, DateTime time}) | 42 | Change.clear({this.$new, this.$old, this.batch, DateTime time}) |
43 | : op = ListChangeOp.clear, | 43 | : op = ListChangeOp.clear, |
44 | pos = null, | 44 | pos = null, |
45 | - item = null, | 45 | + |
46 | time = time ?? new DateTime.now(); | 46 | time = time ?? new DateTime.now(); |
47 | } | 47 | } |
48 | 48 |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | import 'package:get/src/rx/rx_interface.dart'; | 2 | import 'package:get/src/rx/rx_interface.dart'; |
3 | -import '../get_main.dart'; | ||
4 | import 'rx_impl.dart'; | 3 | import 'rx_impl.dart'; |
5 | 4 | ||
6 | Widget obx(Widget Function() builder) { | 5 | Widget obx(Widget Function() builder) { |
@@ -8,7 +7,7 @@ Widget obx(Widget Function() builder) { | @@ -8,7 +7,7 @@ Widget obx(Widget Function() builder) { | ||
8 | return Obxx(b); | 7 | return Obxx(b); |
9 | } | 8 | } |
10 | 9 | ||
11 | -/// it's very very very very experimental, or now, it's just tests. | 10 | +/// it's very very very very experimental |
12 | class Obxx extends StatelessWidget { | 11 | class Obxx extends StatelessWidget { |
13 | final Widget Function() builder; | 12 | final Widget Function() builder; |
14 | Obxx(this.builder, {Key key}) : super(key: key); | 13 | Obxx(this.builder, {Key key}) : super(key: key); |
@@ -17,10 +16,10 @@ class Obxx extends StatelessWidget { | @@ -17,10 +16,10 @@ class Obxx extends StatelessWidget { | ||
17 | @override | 16 | @override |
18 | Widget build(_) { | 17 | Widget build(_) { |
19 | _observer.subject.stream.listen((data) => (_ as Element)..markNeedsBuild()); | 18 | _observer.subject.stream.listen((data) => (_ as Element)..markNeedsBuild()); |
20 | - final observer = Get.obs; | ||
21 | - Get.obs = _observer; | 19 | + final observer = getObs; |
20 | + getObs = _observer; | ||
22 | final result = builder(); | 21 | final result = builder(); |
23 | - Get.obs = observer; | 22 | + getObs = observer; |
24 | return result; | 23 | return result; |
25 | } | 24 | } |
26 | } | 25 | } |
@@ -41,9 +40,7 @@ class _ObxState extends State<Obx> { | @@ -41,9 +40,7 @@ class _ObxState extends State<Obx> { | ||
41 | 40 | ||
42 | @override | 41 | @override |
43 | void initState() { | 42 | void initState() { |
44 | - _observer.subject.stream.listen((data) { | ||
45 | - setState(() {}); | ||
46 | - }); | 43 | + _observer.subject.stream.listen((data) => setState(() {})); |
47 | super.initState(); | 44 | super.initState(); |
48 | } | 45 | } |
49 | 46 | ||
@@ -55,10 +52,10 @@ class _ObxState extends State<Obx> { | @@ -55,10 +52,10 @@ class _ObxState extends State<Obx> { | ||
55 | 52 | ||
56 | @override | 53 | @override |
57 | Widget build(BuildContext context) { | 54 | Widget build(BuildContext context) { |
58 | - final observer = Get.obs; | ||
59 | - Get.obs = this._observer; | 55 | + final observer = getObs; |
56 | + getObs = _observer; | ||
60 | final result = widget.builder(); | 57 | final result = widget.builder(); |
61 | - Get.obs = observer; | 58 | + getObs = observer; |
62 | return result; | 59 | return result; |
63 | } | 60 | } |
64 | } | 61 | } |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | import 'package:flutter/widgets.dart'; | 2 | import 'package:flutter/widgets.dart'; |
3 | +import 'package:get/src/root/smart_management.dart'; | ||
3 | import 'package:get/src/rx/rx_interface.dart'; | 4 | import 'package:get/src/rx/rx_interface.dart'; |
4 | import '../get_main.dart'; | 5 | import '../get_main.dart'; |
5 | 6 | ||
@@ -69,12 +70,11 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -69,12 +70,11 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
69 | bool isRegistred = Get.isRegistred<T>(); | 70 | bool isRegistred = Get.isRegistred<T>(); |
70 | 71 | ||
71 | if (isPrepared) { | 72 | if (isPrepared) { |
72 | - isCreator = true; | 73 | + if (Get().smartManagement != SmartManagement.keepFactory) { |
74 | + isCreator = true; | ||
75 | + } | ||
73 | controller = Get.find<T>(); | 76 | controller = Get.find<T>(); |
74 | - real = RealState( | ||
75 | - updater: setState, | ||
76 | - id: widget.id, | ||
77 | - ); | 77 | + real = RealState(updater: setState, id: widget.id); |
78 | controller._allStates.add(real); | 78 | controller._allStates.add(real); |
79 | } else if (isRegistred) { | 79 | } else if (isRegistred) { |
80 | controller = Get.find<T>(); | 80 | controller = Get.find<T>(); |
@@ -84,7 +84,6 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -84,7 +84,6 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
84 | } else { | 84 | } else { |
85 | controller = widget.init; | 85 | controller = widget.init; |
86 | isCreator = true; | 86 | isCreator = true; |
87 | - | ||
88 | real = RealState(updater: setState, id: widget.id); | 87 | real = RealState(updater: setState, id: widget.id); |
89 | controller._allStates.add(real); | 88 | controller._allStates.add(real); |
90 | Get.put<T>(controller); | 89 | Get.put<T>(controller); |
@@ -97,9 +96,9 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -97,9 +96,9 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
97 | controller?.onInit(); | 96 | controller?.onInit(); |
98 | } | 97 | } |
99 | if (widget.initState != null) widget.initState(this); | 98 | if (widget.initState != null) widget.initState(this); |
100 | - // if (isCreator) { | ||
101 | - // controller?.onInit(); | ||
102 | - // } | 99 | + if (isCreator && Get().smartManagement == SmartManagement.onlyBuilder) { |
100 | + controller?.onInit(); | ||
101 | + } | ||
103 | } | 102 | } |
104 | 103 | ||
105 | @override | 104 | @override |
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.11.1 | 3 | +version: 2.11.2 |
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