Showing
10 changed files
with
107 additions
and
21 deletions
1 | +## [2.7.0] | ||
2 | +- Added obx, a simple state interceptor. | ||
3 | +- Improve Bindings, ListX, and fix docs typos | ||
4 | + | ||
1 | ## [2.6.3] | 5 | ## [2.6.3] |
2 | - Flutter currently has a problem on some devices where using showModalBottomSheet() can cause TextFields to be hidden behind the keyboard (https://github.com/flutter/flutter/issues/18564) this issue is closed, even users reporting that the problem still occurs. | 6 | - Flutter currently has a problem on some devices where using showModalBottomSheet() can cause TextFields to be hidden behind the keyboard (https://github.com/flutter/flutter/issues/18564) this issue is closed, even users reporting that the problem still occurs. |
3 | The problem happens casually, as well as the problem of the snackbar on the iPhone SE 2, and checking the code, I realized that a padding with MediaQuery.of(context).viewInsets.bottom is missing inside the bottomSheet to make it work correctly, since it does not have any constraint with the keyboard. | 7 | The problem happens casually, as well as the problem of the snackbar on the iPhone SE 2, and checking the code, I realized that a padding with MediaQuery.of(context).viewInsets.bottom is missing inside the bottomSheet to make it work correctly, since it does not have any constraint with the keyboard. |
@@ -905,13 +905,13 @@ You can create Global settings for Get. Just add Get.config to your code before | @@ -905,13 +905,13 @@ You can create Global settings for Get. Just add Get.config to your code before | ||
905 | 905 | ||
906 | ```dart | 906 | ```dart |
907 | 907 | ||
908 | -GetMaterialApp( | ||
909 | - enableLog: true, | ||
910 | - defaultTransition: Transitions.fade, | ||
911 | - defaultOpaqueRoute: Get.isOpaqueRouteDefault, | ||
912 | - defaultPopGesture: Get.isPopGestureEnable, | ||
913 | - defaultDurationTransition: Get.defaultDurationTransition, | ||
914 | - defaultGlobalState: Get.defaultGlobalState, | 908 | +GetMaterialApp( |
909 | + enableLog: true, | ||
910 | + defaultTransition: Transition.fade, | ||
911 | + opaqueRoute: Get.isOpaqueRouteDefault, | ||
912 | + popGesture: Get.isPopGestureEnable, | ||
913 | + transitionDuration: Get.defaultDurationTransition, | ||
914 | + defaultGlobalState: Get.defaultGlobalState, | ||
915 | ); | 915 | ); |
916 | 916 | ||
917 | Get.config( | 917 | Get.config( |
@@ -9,6 +9,7 @@ export 'src/state/get_state.dart'; | @@ -9,6 +9,7 @@ export 'src/state/get_state.dart'; | ||
9 | export 'src/rx/rx_interface.dart'; | 9 | export 'src/rx/rx_interface.dart'; |
10 | export 'src/rx/rx_impl.dart'; | 10 | export 'src/rx/rx_impl.dart'; |
11 | export 'src/rx/rx_event.dart'; | 11 | export 'src/rx/rx_event.dart'; |
12 | +export 'src/rx/rx_obx.dart'; | ||
12 | export 'src/rx/rx_getbuilder.dart'; | 13 | export 'src/rx/rx_getbuilder.dart'; |
13 | export 'src/root/root_widget.dart'; | 14 | export 'src/root/root_widget.dart'; |
14 | export 'src/routes/default_route.dart'; | 15 | export 'src/routes/default_route.dart'; |
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/src/routes/bindings_interface.dart'; | 4 | import 'package:get/src/routes/bindings_interface.dart'; |
4 | import 'bottomsheet/bottomsheet.dart'; | 5 | import 'bottomsheet/bottomsheet.dart'; |
5 | import 'platform/platform.dart'; | 6 | import 'platform/platform.dart'; |
@@ -721,6 +722,12 @@ class Get { | @@ -721,6 +722,12 @@ class Get { | ||
721 | static void remove<S>({String name}) { | 722 | static void remove<S>({String name}) { |
722 | String key = _getKey(S, name); | 723 | String key = _getKey(S, name); |
723 | _FcBuilder builder = Get()._singl[key]; | 724 | _FcBuilder builder = Get()._singl[key]; |
725 | + final i = builder.dependency; | ||
726 | + | ||
727 | + if (i is DisposableInterface || i is GetController) { | ||
728 | + i.onClose(); | ||
729 | + if (isLogEnable) print('[GET] onClose of $key called'); | ||
730 | + } | ||
724 | if (builder != null) builder.dependency = null; | 731 | if (builder != null) builder.dependency = null; |
725 | if (Get()._singl.containsKey(key)) { | 732 | if (Get()._singl.containsKey(key)) { |
726 | print('error on remove $key'); | 733 | print('error on remove $key'); |
@@ -739,13 +746,22 @@ class Get { | @@ -739,13 +746,22 @@ class Get { | ||
739 | } | 746 | } |
740 | 747 | ||
741 | /// Delete class instance on [S] and clean memory | 748 | /// Delete class instance on [S] and clean memory |
742 | - static bool delete<S>({String name}) { | 749 | + static Future<bool> delete<S>({String name}) async { |
743 | String key = _getKey(S, name); | 750 | String key = _getKey(S, name); |
744 | 751 | ||
745 | if (!Get()._singl.containsKey(key)) { | 752 | if (!Get()._singl.containsKey(key)) { |
746 | print('Instance $key not found'); | 753 | print('Instance $key not found'); |
747 | return false; | 754 | return false; |
748 | } | 755 | } |
756 | + | ||
757 | + _FcBuilder builder = Get()._singl[key]; | ||
758 | + final i = builder.dependency; | ||
759 | + | ||
760 | + if (i is DisposableInterface || i is GetController) { | ||
761 | + await i.onClose(); | ||
762 | + if (isLogEnable) print('[GET] onClose of $key called'); | ||
763 | + } | ||
764 | + | ||
749 | Get()._singl.removeWhere((oldkey, value) => (oldkey == key)); | 765 | Get()._singl.removeWhere((oldkey, value) => (oldkey == key)); |
750 | if (Get()._singl.containsKey(key)) { | 766 | if (Get()._singl.containsKey(key)) { |
751 | print('error on remove object $key'); | 767 | print('error on remove object $key'); |
@@ -766,7 +782,7 @@ class Get { | @@ -766,7 +782,7 @@ class Get { | ||
766 | 782 | ||
767 | static RouteSettings get routeSettings => Get()._settings; | 783 | static RouteSettings get routeSettings => Get()._settings; |
768 | 784 | ||
769 | - Routing _routing; | 785 | + Routing _routing = Routing(); |
770 | 786 | ||
771 | Map<String, String> _parameters = {}; | 787 | Map<String, String> _parameters = {}; |
772 | 788 | ||
@@ -860,6 +876,9 @@ class Get { | @@ -860,6 +876,9 @@ class Get { | ||
860 | /// give access to Theme.of(context).iconTheme.color | 876 | /// give access to Theme.of(context).iconTheme.color |
861 | static Color get iconColor => Theme.of(context).iconTheme.color; | 877 | static Color get iconColor => Theme.of(context).iconTheme.color; |
862 | 878 | ||
879 | + /// give access to Focus.of(context).iconTheme.color | ||
880 | + static FocusScopeNode get focusScope => FocusScope.of(context); | ||
881 | + | ||
863 | /// give access to MediaQuery.of(context).size.height | 882 | /// give access to MediaQuery.of(context).size.height |
864 | static double get height => MediaQuery.of(context).size.height; | 883 | static double get height => MediaQuery.of(context).size.height; |
865 | 884 |
@@ -75,11 +75,11 @@ class _GetXState<T extends RxController> extends State<GetX<T>> { | @@ -75,11 +75,11 @@ class _GetXState<T extends RxController> extends State<GetX<T>> { | ||
75 | 75 | ||
76 | if (isCreator) { | 76 | if (isCreator) { |
77 | if (widget.autoRemove && Get.isRegistred<T>()) { | 77 | if (widget.autoRemove && Get.isRegistred<T>()) { |
78 | - controller.onClose(); | 78 | + // controller.onClose(); |
79 | Get.delete<T>(); | 79 | Get.delete<T>(); |
80 | } | 80 | } |
81 | - } else { | ||
82 | - controller.onClose(); | 81 | + // } else { |
82 | + // controller.onClose(); | ||
83 | } | 83 | } |
84 | // controller.onClose(); | 84 | // controller.onClose(); |
85 | _observer.close(); | 85 | _observer.close(); |
@@ -245,6 +245,13 @@ class ListX<E> extends DelegatingList<E> implements List<E>, RxInterface<E> { | @@ -245,6 +245,13 @@ class ListX<E> extends DelegatingList<E> implements List<E>, RxInterface<E> { | ||
245 | }); | 245 | }); |
246 | } | 246 | } |
247 | 247 | ||
248 | + // @override | ||
249 | + // int get length => list.length; | ||
250 | + | ||
251 | + // List<E> get list => value as List<E>; | ||
252 | + | ||
253 | + // set list(List<E> v) => assignAll(v); | ||
254 | + | ||
248 | @override | 255 | @override |
249 | get value { | 256 | get value { |
250 | if (Get.obs != null) { | 257 | if (Get.obs != null) { |
@@ -375,12 +382,12 @@ extension MapExtension on Map { | @@ -375,12 +382,12 @@ extension MapExtension on Map { | ||
375 | } | 382 | } |
376 | } | 383 | } |
377 | 384 | ||
378 | -extension ListExtension on List { | ||
379 | - ListX get obs { | 385 | +extension ListExtension<E> on List<E> { |
386 | + ListX<E> get obs { | ||
380 | if (this != null) | 387 | if (this != null) |
381 | - return ListX()..assignAll(this); | 388 | + return ListX<E>()..assignAll(this); |
382 | else | 389 | else |
383 | - return ListX(null); | 390 | + return ListX<E>(null); |
384 | } | 391 | } |
385 | } | 392 | } |
386 | 393 |
lib/src/rx/rx_obx.dart
0 → 100644
1 | +import 'dart:async'; | ||
2 | +import 'package:flutter/widgets.dart'; | ||
3 | +import 'package:get/src/rx/rx_interface.dart'; | ||
4 | +import '../get_main.dart'; | ||
5 | +import 'rx_impl.dart'; | ||
6 | + | ||
7 | +Widget obx(Widget Function() builder) { | ||
8 | + final b = builder; | ||
9 | + return Obx( | ||
10 | + builder: b, | ||
11 | + ); | ||
12 | +} | ||
13 | + | ||
14 | +class Obx extends StatefulWidget { | ||
15 | + final Widget Function() builder; | ||
16 | + | ||
17 | + const Obx({ | ||
18 | + this.builder, | ||
19 | + }); | ||
20 | + _ObxState createState() => _ObxState(); | ||
21 | +} | ||
22 | + | ||
23 | +class _ObxState extends State<Obx> { | ||
24 | + RxInterface _observer; | ||
25 | + StreamSubscription _listenSubscription; | ||
26 | + bool isCreator = false; | ||
27 | + | ||
28 | + _ObxState() { | ||
29 | + _observer = ListX(); | ||
30 | + } | ||
31 | + | ||
32 | + @override | ||
33 | + void initState() { | ||
34 | + _listenSubscription = _observer.subject.stream.listen((data) { | ||
35 | + setState(() {}); | ||
36 | + }); | ||
37 | + super.initState(); | ||
38 | + } | ||
39 | + | ||
40 | + @override | ||
41 | + void dispose() { | ||
42 | + _observer.close(); | ||
43 | + _listenSubscription?.cancel(); | ||
44 | + super.dispose(); | ||
45 | + } | ||
46 | + | ||
47 | + @override | ||
48 | + Widget build(BuildContext context) { | ||
49 | + final observer = Get.obs; | ||
50 | + Get.obs = this._observer; | ||
51 | + final result = widget.builder(); | ||
52 | + Get.obs = observer; | ||
53 | + return result; | ||
54 | + } | ||
55 | +} |
@@ -34,8 +34,8 @@ class GetController extends State { | @@ -34,8 +34,8 @@ class GetController extends State { | ||
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | - void onClose() {} | ||
38 | - void onInit() {} | 37 | + void onClose() async {} |
38 | + void onInit() async {} | ||
39 | 39 | ||
40 | @override | 40 | @override |
41 | Widget build(_) => throw ("build method can't be called"); | 41 | Widget build(_) => throw ("build method can't be called"); |
@@ -107,7 +107,7 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -107,7 +107,7 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
107 | try { | 107 | try { |
108 | controller?.onInit(); | 108 | controller?.onInit(); |
109 | } catch (e) { | 109 | } catch (e) { |
110 | - if (Get.isLogEnable) print("Controller is not attach"); | 110 | + if (Get.isLogEnable) print("[GET] error: $e"); |
111 | } | 111 | } |
112 | } | 112 | } |
113 | } | 113 | } |
@@ -120,7 +120,7 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -120,7 +120,7 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
120 | 120 | ||
121 | if (isCreator) { | 121 | if (isCreator) { |
122 | if (widget.autoRemove && Get.isRegistred<T>()) { | 122 | if (widget.autoRemove && Get.isRegistred<T>()) { |
123 | - controller.onClose(); | 123 | + // controller.onClose(); |
124 | controller._allStates.remove(real); | 124 | controller._allStates.remove(real); |
125 | Get.delete<T>(); | 125 | Get.delete<T>(); |
126 | } | 126 | } |
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.6.3 | 3 | +version: 2.7.0 |
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