Committed by
GitHub
Bump to 2.11.1
Fix onInit called only once on SmartManagement.onlyBuilder
Showing
7 changed files
with
47 additions
and
38 deletions
| 1 | +## [2.11.1] | ||
| 2 | +- Fixed: oninit calling only once. | ||
| 3 | + | ||
| 1 | ## [2.11.0] | 4 | ## [2.11.0] |
| 2 | - Added Permissions: | 5 | - Added Permissions: |
| 3 | You can now revoke permissions to SmartManagement so that it cannot delete a particular controller. | 6 | You can now revoke permissions to SmartManagement so that it cannot delete a particular controller. |
| @@ -13,10 +13,10 @@ export 'src/rx/rx_event.dart'; | @@ -13,10 +13,10 @@ export 'src/rx/rx_event.dart'; | ||
| 13 | export 'src/rx/rx_obx.dart'; | 13 | export 'src/rx/rx_obx.dart'; |
| 14 | export 'src/rx/rx_getbuilder.dart'; | 14 | export 'src/rx/rx_getbuilder.dart'; |
| 15 | export 'src/root/root_widget.dart'; | 15 | export 'src/root/root_widget.dart'; |
| 16 | +export 'src/root/smart_management.dart'; | ||
| 16 | export 'src/routes/default_route.dart'; | 17 | export 'src/routes/default_route.dart'; |
| 17 | export 'src/routes/get_route.dart'; | 18 | export 'src/routes/get_route.dart'; |
| 18 | export 'src/routes/bindings_interface.dart'; | 19 | export 'src/routes/bindings_interface.dart'; |
| 19 | export 'src/routes/observers/route_observer.dart'; | 20 | export 'src/routes/observers/route_observer.dart'; |
| 20 | export 'src/routes/transitions_type.dart'; | 21 | export 'src/routes/transitions_type.dart'; |
| 21 | export 'src/platform/platform.dart'; | 22 | export 'src/platform/platform.dart'; |
| 22 | - |
| @@ -729,7 +729,7 @@ class Get { | @@ -729,7 +729,7 @@ class Get { | ||
| 729 | return Get().routesKey.containsKey(key); | 729 | return Get().routesKey.containsKey(key); |
| 730 | } | 730 | } |
| 731 | 731 | ||
| 732 | - registerRouteInstance<S>({String tag}) { | 732 | + void registerRouteInstance<S>({String tag}) { |
| 733 | // print("Register route [$S] as ${Get.currentRoute}"); | 733 | // print("Register route [$S] as ${Get.currentRoute}"); |
| 734 | Get().routesKey.putIfAbsent(_getKey(S, tag), () => Get.currentRoute); | 734 | Get().routesKey.putIfAbsent(_getKey(S, tag), () => Get.currentRoute); |
| 735 | } | 735 | } |
| @@ -754,7 +754,8 @@ class Get { | @@ -754,7 +754,8 @@ class Get { | ||
| 754 | String key = _getKey(S, tag); | 754 | String key = _getKey(S, tag); |
| 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().registerRouteInstance<S>(tag: tag); | 759 | Get().registerRouteInstance<S>(tag: tag); |
| 759 | callInit = true; | 760 | callInit = true; |
| 760 | } | 761 | } |
| @@ -779,7 +780,8 @@ class Get { | @@ -779,7 +780,8 @@ class Get { | ||
| 779 | if (isLogEnable) print('[GET] $S instance was created at that time'); | 780 | if (isLogEnable) print('[GET] $S instance was created at that time'); |
| 780 | S _value = Get.put<S>(Get()._factory[key].call() as S); | 781 | S _value = Get.put<S>(Get()._factory[key].call() as S); |
| 781 | 782 | ||
| 782 | - if (!isDependencyInit<S>()) { | 783 | + if (!isDependencyInit<S>() && |
| 784 | + Get().smartManagement == SmartManagement.full) { | ||
| 783 | Get().registerRouteInstance<S>(tag: tag); | 785 | Get().registerRouteInstance<S>(tag: tag); |
| 784 | callInit = true; | 786 | callInit = true; |
| 785 | } | 787 | } |
| 1 | -import 'dart:async'; | ||
| 2 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 3 | import 'package:get/src/get_main.dart'; | 2 | import 'package:get/src/get_main.dart'; |
| 3 | +import 'package:get/src/root/smart_management.dart'; | ||
| 4 | import 'rx_impl.dart'; | 4 | import 'rx_impl.dart'; |
| 5 | import 'rx_interface.dart'; | 5 | import 'rx_interface.dart'; |
| 6 | 6 | ||
| @@ -30,7 +30,6 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | @@ -30,7 +30,6 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | ||
| 30 | 30 | ||
| 31 | class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | 31 | class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { |
| 32 | RxInterface _observer; | 32 | RxInterface _observer; |
| 33 | - StreamSubscription _listenSubscription; | ||
| 34 | T controller; | 33 | T controller; |
| 35 | bool isCreator = false; | 34 | bool isCreator = false; |
| 36 | 35 | ||
| @@ -43,9 +42,6 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -43,9 +42,6 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
| 43 | bool isPrepared = Get.isPrepared<T>(); | 42 | bool isPrepared = Get.isPrepared<T>(); |
| 44 | bool isRegistred = Get.isRegistred<T>(); | 43 | bool isRegistred = Get.isRegistred<T>(); |
| 45 | if (widget.global) { | 44 | if (widget.global) { |
| 46 | - // if (Get().smartManagement == SmartManagement.full) { | ||
| 47 | - // Get.isDependencyInit<T>(); | ||
| 48 | - // } | ||
| 49 | if (isPrepared) { | 45 | if (isPrepared) { |
| 50 | isCreator = true; | 46 | isCreator = true; |
| 51 | controller = Get.find<T>(); | 47 | controller = Get.find<T>(); |
| @@ -63,11 +59,11 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -63,11 +59,11 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
| 63 | controller?.onInit(); | 59 | controller?.onInit(); |
| 64 | } | 60 | } |
| 65 | if (widget.initState != null) widget.initState(this); | 61 | if (widget.initState != null) widget.initState(this); |
| 66 | - // if (isCreator) { | ||
| 67 | - // controller?.onInit(); | ||
| 68 | - // } | 62 | + if (isCreator && Get().smartManagement == SmartManagement.onlyBuilder) { |
| 63 | + controller?.onInit(); | ||
| 64 | + } | ||
| 69 | 65 | ||
| 70 | - _listenSubscription = _observer.subject.stream.listen((data) { | 66 | + _observer.subject.stream.listen((data) { |
| 71 | setState(() {}); | 67 | setState(() {}); |
| 72 | }); | 68 | }); |
| 73 | super.initState(); | 69 | super.initState(); |
| @@ -87,8 +83,6 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -87,8 +83,6 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
| 87 | } | 83 | } |
| 88 | // controller.onClose(); | 84 | // controller.onClose(); |
| 89 | _observer.close(); | 85 | _observer.close(); |
| 90 | - _listenSubscription?.cancel(); | ||
| 91 | - | ||
| 92 | controller = null; | 86 | controller = null; |
| 93 | isCreator = null; | 87 | isCreator = null; |
| 94 | super.dispose(); | 88 | super.dispose(); |
| @@ -4,10 +4,9 @@ import 'rx_callbacks.dart'; | @@ -4,10 +4,9 @@ import 'rx_callbacks.dart'; | ||
| 4 | import 'rx_interface.dart'; | 4 | import 'rx_interface.dart'; |
| 5 | import 'rx_model.dart'; | 5 | import 'rx_model.dart'; |
| 6 | 6 | ||
| 7 | -class _StoredValue<T> implements RxInterface<T> { | 7 | +class _RxImpl<T> implements RxInterface<T> { |
| 8 | StreamController<Change<T>> subject = StreamController<Change<T>>.broadcast(); | 8 | StreamController<Change<T>> subject = StreamController<Change<T>>.broadcast(); |
| 9 | - StreamController<Change<T>> _changeCtl = | ||
| 10 | - StreamController<Change<T>>.broadcast(); | 9 | + StreamController<Change<T>> _changeCtl = StreamController<Change<T>>(); |
| 11 | Map<Stream<Change<T>>, StreamSubscription> _subscriptions = Map(); | 10 | Map<Stream<Change<T>>, StreamSubscription> _subscriptions = Map(); |
| 12 | 11 | ||
| 13 | T _value; | 12 | T _value; |
| @@ -50,7 +49,7 @@ class _StoredValue<T> implements RxInterface<T> { | @@ -50,7 +49,7 @@ class _StoredValue<T> implements RxInterface<T> { | ||
| 50 | 49 | ||
| 51 | int _cb = 0; | 50 | int _cb = 0; |
| 52 | 51 | ||
| 53 | - _StoredValue([T initial]) : _value = initial { | 52 | + _RxImpl([T initial]) : _value = initial { |
| 54 | _onChange = subject.stream.asBroadcastStream(); | 53 | _onChange = subject.stream.asBroadcastStream(); |
| 55 | } | 54 | } |
| 56 | 55 | ||
| @@ -91,28 +90,28 @@ class _StoredValue<T> implements RxInterface<T> { | @@ -91,28 +90,28 @@ class _StoredValue<T> implements RxInterface<T> { | ||
| 91 | Stream<R> map<R>(R mapper(T data)) => stream.map(mapper); | 90 | Stream<R> map<R>(R mapper(T data)) => stream.map(mapper); |
| 92 | } | 91 | } |
| 93 | 92 | ||
| 94 | -class StringX<String> extends _StoredValue<String> { | 93 | +class StringX<String> extends _RxImpl<String> { |
| 95 | StringX([String initial]) { | 94 | StringX([String initial]) { |
| 96 | _value = initial; | 95 | _value = initial; |
| 97 | _onChange = subject.stream.asBroadcastStream(); | 96 | _onChange = subject.stream.asBroadcastStream(); |
| 98 | } | 97 | } |
| 99 | } | 98 | } |
| 100 | 99 | ||
| 101 | -class IntX<int> extends _StoredValue<int> { | 100 | +class IntX<int> extends _RxImpl<int> { |
| 102 | IntX([int initial]) { | 101 | IntX([int initial]) { |
| 103 | _value = initial; | 102 | _value = initial; |
| 104 | _onChange = subject.stream.asBroadcastStream(); | 103 | _onChange = subject.stream.asBroadcastStream(); |
| 105 | } | 104 | } |
| 106 | } | 105 | } |
| 107 | 106 | ||
| 108 | -class MapX<Map> extends _StoredValue<Map> { | 107 | +class MapX<Map> extends _RxImpl<Map> { |
| 109 | MapX([Map initial]) { | 108 | MapX([Map initial]) { |
| 110 | _value = initial; | 109 | _value = initial; |
| 111 | _onChange = subject.stream.asBroadcastStream(); | 110 | _onChange = subject.stream.asBroadcastStream(); |
| 112 | } | 111 | } |
| 113 | } | 112 | } |
| 114 | 113 | ||
| 115 | -// class ListX<List> extends _StoredValue<List> { | 114 | +// class ListX<List> extends _RxImpl<List> { |
| 116 | // ListX([List initial]) { | 115 | // ListX([List initial]) { |
| 117 | // _value = initial; | 116 | // _value = initial; |
| 118 | // _onChange = subject.stream.asBroadcastStream(); | 117 | // _onChange = subject.stream.asBroadcastStream(); |
| @@ -529,28 +528,28 @@ typedef E ChildrenListComposer<S, E>(S value); | @@ -529,28 +528,28 @@ typedef E ChildrenListComposer<S, E>(S value); | ||
| 529 | // } | 528 | // } |
| 530 | // } | 529 | // } |
| 531 | 530 | ||
| 532 | -class BoolX<bool> extends _StoredValue<bool> { | 531 | +class BoolX<bool> extends _RxImpl<bool> { |
| 533 | BoolX([bool initial]) { | 532 | BoolX([bool initial]) { |
| 534 | _value = initial; | 533 | _value = initial; |
| 535 | _onChange = subject.stream.asBroadcastStream(); | 534 | _onChange = subject.stream.asBroadcastStream(); |
| 536 | } | 535 | } |
| 537 | } | 536 | } |
| 538 | 537 | ||
| 539 | -class DoubleX<double> extends _StoredValue<double> { | 538 | +class DoubleX<double> extends _RxImpl<double> { |
| 540 | DoubleX([double initial]) { | 539 | DoubleX([double initial]) { |
| 541 | _value = initial; | 540 | _value = initial; |
| 542 | _onChange = subject.stream.asBroadcastStream(); | 541 | _onChange = subject.stream.asBroadcastStream(); |
| 543 | } | 542 | } |
| 544 | } | 543 | } |
| 545 | 544 | ||
| 546 | -class NumX<num> extends _StoredValue<num> { | 545 | +class NumX<num> extends _RxImpl<num> { |
| 547 | NumX([num initial]) { | 546 | NumX([num initial]) { |
| 548 | _value = initial; | 547 | _value = initial; |
| 549 | _onChange = subject.stream.asBroadcastStream(); | 548 | _onChange = subject.stream.asBroadcastStream(); |
| 550 | } | 549 | } |
| 551 | } | 550 | } |
| 552 | 551 | ||
| 553 | -class Rx<T> extends _StoredValue<T> { | 552 | +class Rx<T> extends _RxImpl<T> { |
| 554 | Rx([T initial]) { | 553 | Rx([T initial]) { |
| 555 | _value = initial; | 554 | _value = initial; |
| 556 | _onChange = subject.stream.asBroadcastStream(); | 555 | _onChange = subject.stream.asBroadcastStream(); |
| 1 | -import 'dart:async'; | ||
| 2 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 3 | import 'package:get/src/rx/rx_interface.dart'; | 2 | import 'package:get/src/rx/rx_interface.dart'; |
| 4 | import '../get_main.dart'; | 3 | import '../get_main.dart'; |
| @@ -6,30 +5,43 @@ import 'rx_impl.dart'; | @@ -6,30 +5,43 @@ import 'rx_impl.dart'; | ||
| 6 | 5 | ||
| 7 | Widget obx(Widget Function() builder) { | 6 | Widget obx(Widget Function() builder) { |
| 8 | final b = builder; | 7 | final b = builder; |
| 9 | - return Obx(b); | 8 | + return Obxx(b); |
| 9 | +} | ||
| 10 | + | ||
| 11 | +/// it's very very very very experimental, or now, it's just tests. | ||
| 12 | +class Obxx extends StatelessWidget { | ||
| 13 | + final Widget Function() builder; | ||
| 14 | + Obxx(this.builder, {Key key}) : super(key: key); | ||
| 15 | + final RxInterface _observer = Rx(); | ||
| 16 | + | ||
| 17 | + @override | ||
| 18 | + Widget build(_) { | ||
| 19 | + _observer.subject.stream.listen((data) => (_ as Element)..markNeedsBuild()); | ||
| 20 | + final observer = Get.obs; | ||
| 21 | + Get.obs = _observer; | ||
| 22 | + final result = builder(); | ||
| 23 | + Get.obs = observer; | ||
| 24 | + return result; | ||
| 25 | + } | ||
| 10 | } | 26 | } |
| 11 | 27 | ||
| 12 | class Obx extends StatefulWidget { | 28 | class Obx extends StatefulWidget { |
| 13 | final Widget Function() builder; | 29 | final Widget Function() builder; |
| 14 | 30 | ||
| 15 | - const Obx( | ||
| 16 | - this.builder, | ||
| 17 | - ); | 31 | + const Obx(this.builder); |
| 18 | _ObxState createState() => _ObxState(); | 32 | _ObxState createState() => _ObxState(); |
| 19 | } | 33 | } |
| 20 | 34 | ||
| 21 | class _ObxState extends State<Obx> { | 35 | class _ObxState extends State<Obx> { |
| 22 | RxInterface _observer; | 36 | RxInterface _observer; |
| 23 | - StreamSubscription _listenSubscription; | ||
| 24 | - bool isCreator = false; | ||
| 25 | 37 | ||
| 26 | _ObxState() { | 38 | _ObxState() { |
| 27 | - _observer = ListX(); | 39 | + _observer = Rx(); |
| 28 | } | 40 | } |
| 29 | 41 | ||
| 30 | @override | 42 | @override |
| 31 | void initState() { | 43 | void initState() { |
| 32 | - _listenSubscription = _observer.subject.stream.listen((data) { | 44 | + _observer.subject.stream.listen((data) { |
| 33 | setState(() {}); | 45 | setState(() {}); |
| 34 | }); | 46 | }); |
| 35 | super.initState(); | 47 | super.initState(); |
| @@ -38,7 +50,6 @@ class _ObxState extends State<Obx> { | @@ -38,7 +50,6 @@ class _ObxState extends State<Obx> { | ||
| 38 | @override | 50 | @override |
| 39 | void dispose() { | 51 | void dispose() { |
| 40 | _observer.close(); | 52 | _observer.close(); |
| 41 | - _listenSubscription?.cancel(); | ||
| 42 | super.dispose(); | 53 | super.dispose(); |
| 43 | } | 54 | } |
| 44 | 55 |
| 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.0 | 3 | +version: 2.11.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