Showing
14 changed files
with
92 additions
and
73 deletions
1 | +## [3.16.1] | ||
2 | +- Fix compilation error on master | ||
3 | + | ||
1 | ## [3.16.0] | 4 | ## [3.16.0] |
2 | - Documentation translated into Russian language. (@Renat Fakhrutdinov, @Doaxan and @BatttA) | 5 | - Documentation translated into Russian language. (@Renat Fakhrutdinov, @Doaxan and @BatttA) |
3 | - Added error message callback for StateMixin (@eduardoflorence) | 6 | - Added error message callback for StateMixin (@eduardoflorence) |
@@ -43,8 +43,8 @@ class BindingsBuilder<T> extends Bindings { | @@ -43,8 +43,8 @@ class BindingsBuilder<T> extends Bindings { | ||
43 | /// ``` | 43 | /// ``` |
44 | factory BindingsBuilder.put(InstanceBuilderCallback<T> builder, | 44 | factory BindingsBuilder.put(InstanceBuilderCallback<T> builder, |
45 | {String tag, bool permanent = false}) { | 45 | {String tag, bool permanent = false}) { |
46 | - return BindingsBuilder(() => GetInstance() | ||
47 | - .put<T>(null, tag: tag, permanent: permanent, builder: builder)); | 46 | + return BindingsBuilder( |
47 | + () => GetInstance().put<T>(builder(), tag: tag, permanent: permanent)); | ||
48 | } | 48 | } |
49 | 49 | ||
50 | /// WARNING: don't use `()=> Get.put(Controller())`, | 50 | /// WARNING: don't use `()=> Get.put(Controller())`, |
@@ -83,8 +83,7 @@ extension Inst on GetInterface { | @@ -83,8 +83,7 @@ extension Inst on GetInterface { | ||
83 | {String tag, | 83 | {String tag, |
84 | bool permanent = false, | 84 | bool permanent = false, |
85 | InstanceBuilderCallback<S> builder}) => | 85 | InstanceBuilderCallback<S> builder}) => |
86 | - GetInstance() | ||
87 | - .put<S>(dependency, tag: tag, permanent: permanent, builder: builder); | 86 | + GetInstance().put<S>(dependency, tag: tag, permanent: permanent); |
88 | 87 | ||
89 | /// Clears all registered instances (and/or tags). | 88 | /// Clears all registered instances (and/or tags). |
90 | /// Even the persistent ones. | 89 | /// Even the persistent ones. |
1 | -import 'dart:ui'; | 1 | +import 'dart:ui' as ui; |
2 | 2 | ||
3 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
4 | import 'package:flutter/scheduler.dart'; | 4 | import 'package:flutter/scheduler.dart'; |
@@ -229,7 +229,8 @@ extension ExtensionDialog on GetInterface { | @@ -229,7 +229,8 @@ extension ExtensionDialog on GetInterface { | ||
229 | assert(useRootNavigator != null); | 229 | assert(useRootNavigator != null); |
230 | assert(debugCheckHasMaterialLocalizations(context)); | 230 | assert(debugCheckHasMaterialLocalizations(context)); |
231 | 231 | ||
232 | - final theme = Theme.of(context, shadowThemeOnly: true); | 232 | + // final theme = Theme.of(context, shadowThemeOnly: true); |
233 | + final theme = Theme.of(context); | ||
233 | return generalDialog<T>( | 234 | return generalDialog<T>( |
234 | pageBuilder: (buildContext, animation, secondaryAnimation) { | 235 | pageBuilder: (buildContext, animation, secondaryAnimation) { |
235 | final pageChild = widget; | 236 | final pageChild = widget; |
@@ -425,7 +426,8 @@ extension ExtensionBottomSheet on GetInterface { | @@ -425,7 +426,8 @@ extension ExtensionBottomSheet on GetInterface { | ||
425 | .push(GetModalBottomSheetRoute<T>( | 426 | .push(GetModalBottomSheetRoute<T>( |
426 | builder: (_) => bottomsheet, | 427 | builder: (_) => bottomsheet, |
427 | isPersistent: persistent, | 428 | isPersistent: persistent, |
428 | - theme: Theme.of(key.currentContext, shadowThemeOnly: true), | 429 | + // theme: Theme.of(key.currentContext, shadowThemeOnly: true), |
430 | + theme: Theme.of(key.currentContext), | ||
429 | isScrollControlled: isScrollControlled, | 431 | isScrollControlled: isScrollControlled, |
430 | barrierLabel: | 432 | barrierLabel: |
431 | MaterialLocalizations.of(key.currentContext).modalBarrierDismissLabel, | 433 | MaterialLocalizations.of(key.currentContext).modalBarrierDismissLabel, |
@@ -1042,7 +1044,7 @@ Since version 2.8 it is possible to access the properties | @@ -1042,7 +1044,7 @@ Since version 2.8 it is possible to access the properties | ||
1042 | } | 1044 | } |
1043 | 1045 | ||
1044 | ///The window to which this binding is bound. | 1046 | ///The window to which this binding is bound. |
1045 | - Window get window => engine.window; | 1047 | + ui.Window get window => ui.window; |
1046 | 1048 | ||
1047 | ///The number of device pixels for each logical pixel. | 1049 | ///The number of device pixels for each logical pixel. |
1048 | double get pixelRatio => window.devicePixelRatio; | 1050 | double get pixelRatio => window.devicePixelRatio; |
@@ -5,11 +5,7 @@ part of rx_types; | @@ -5,11 +5,7 @@ part of rx_types; | ||
5 | /// of those `Widgets` and Rx values. | 5 | /// of those `Widgets` and Rx values. |
6 | RxInterface getObs; | 6 | RxInterface getObs; |
7 | 7 | ||
8 | -mixin RxObjectMixin<T> { | ||
9 | - GetStream<T> subject = GetStream<T>(); | ||
10 | - final _subscriptions = <StreamSubscription>[]; | ||
11 | - bool get canUpdate => _subscriptions.isNotEmpty; | ||
12 | - | 8 | +mixin RxObjectMixin<T> on NotifyManager<T> { |
13 | T _value; | 9 | T _value; |
14 | 10 | ||
15 | /// Makes a direct update of [value] adding it to the Stream | 11 | /// Makes a direct update of [value] adding it to the Stream |
@@ -48,15 +44,6 @@ mixin RxObjectMixin<T> { | @@ -48,15 +44,6 @@ mixin RxObjectMixin<T> { | ||
48 | subject.add(_value = null); | 44 | subject.add(_value = null); |
49 | } | 45 | } |
50 | 46 | ||
51 | - /// Closes the subscriptions for this Rx, releasing the resources. | ||
52 | - void close() { | ||
53 | - for (final subscription in _subscriptions) { | ||
54 | - subscription?.cancel(); | ||
55 | - } | ||
56 | - _subscriptions.clear(); | ||
57 | - subject.close(); | ||
58 | - } | ||
59 | - | ||
60 | /// Makes this Rx looks like a function so you can update a new | 47 | /// Makes this Rx looks like a function so you can update a new |
61 | /// value using [rx(someOtherValue)]. Practical to assign the Rx directly | 48 | /// value using [rx(someOtherValue)]. Practical to assign the Rx directly |
62 | /// to some Widget that has a signature ::onChange( value ) | 49 | /// to some Widget that has a signature ::onChange( value ) |
@@ -80,19 +67,6 @@ mixin RxObjectMixin<T> { | @@ -80,19 +67,6 @@ mixin RxObjectMixin<T> { | ||
80 | return value; | 67 | return value; |
81 | } | 68 | } |
82 | 69 | ||
83 | - /// This is an internal method. | ||
84 | - /// Subscribe to changes on the inner stream. | ||
85 | - void addListener(GetStream<T> rxGetx) { | ||
86 | - if (_subscriptions.contains(rxGetx.listen)) { | ||
87 | - return; | ||
88 | - } | ||
89 | - | ||
90 | - final subs = rxGetx.listen((data) { | ||
91 | - subject.add(data); | ||
92 | - }); | ||
93 | - _subscriptions.add(subs); | ||
94 | - } | ||
95 | - | ||
96 | bool firstRebuild = true; | 70 | bool firstRebuild = true; |
97 | 71 | ||
98 | /// Same as `toString()` but using a getter. | 72 | /// Same as `toString()` but using a getter. |
@@ -111,7 +85,7 @@ mixin RxObjectMixin<T> { | @@ -111,7 +85,7 @@ mixin RxObjectMixin<T> { | ||
111 | bool operator ==(dynamic o) { | 85 | bool operator ==(dynamic o) { |
112 | // Todo, find a common implementation for the hashCode of different Types. | 86 | // Todo, find a common implementation for the hashCode of different Types. |
113 | if (o is T) return value == o; | 87 | if (o is T) return value == o; |
114 | - if (o is RxInterface<T>) return value == o.value; | 88 | + if (o is RxObjectMixin<T>) return value == o.value; |
115 | return false; | 89 | return false; |
116 | } | 90 | } |
117 | 91 | ||
@@ -138,6 +112,36 @@ mixin RxObjectMixin<T> { | @@ -138,6 +112,36 @@ mixin RxObjectMixin<T> { | ||
138 | 112 | ||
139 | Stream<T> get stream => GetStreamTransformation<T>(subject.listenable); | 113 | Stream<T> get stream => GetStreamTransformation<T>(subject.listenable); |
140 | 114 | ||
115 | + /// Binds an existing [Stream<T>] to this Rx<T> to keep the values in sync. | ||
116 | + /// You can bind multiple sources to update the value. | ||
117 | + /// Closing the subscription will happen automatically when the observer | ||
118 | + /// Widget ([GetX] or [Obx]) gets unmounted from the Widget tree. | ||
119 | + void bindStream(Stream<T> stream) { | ||
120 | + _subscriptions.add(stream.listen((va) => value = va)); | ||
121 | + } | ||
122 | +} | ||
123 | + | ||
124 | +class RxNotifier<T> = RxInterface<T> with NotifyManager<T>; | ||
125 | + | ||
126 | +mixin NotifyManager<T> { | ||
127 | + GetStream<T> subject = GetStream<T>(); | ||
128 | + final _subscriptions = <StreamSubscription>[]; | ||
129 | + | ||
130 | + bool get canUpdate => _subscriptions.isNotEmpty; | ||
131 | + | ||
132 | + /// This is an internal method. | ||
133 | + /// Subscribe to changes on the inner stream. | ||
134 | + void addListener(GetStream<T> rxGetx) { | ||
135 | + if (_subscriptions.contains(rxGetx.listen)) { | ||
136 | + return; | ||
137 | + } | ||
138 | + | ||
139 | + final subs = rxGetx.listen((data) { | ||
140 | + subject.add(data); | ||
141 | + }); | ||
142 | + _subscriptions.add(subs); | ||
143 | + } | ||
144 | + | ||
141 | StreamSubscription<T> listen( | 145 | StreamSubscription<T> listen( |
142 | void Function(T) onData, { | 146 | void Function(T) onData, { |
143 | Function onError, | 147 | Function onError, |
@@ -147,17 +151,18 @@ mixin RxObjectMixin<T> { | @@ -147,17 +151,18 @@ mixin RxObjectMixin<T> { | ||
147 | subject.listen(onData, | 151 | subject.listen(onData, |
148 | onError: onError, onDone: onDone, cancelOnError: cancelOnError); | 152 | onError: onError, onDone: onDone, cancelOnError: cancelOnError); |
149 | 153 | ||
150 | - /// Binds an existing [Stream<T>] to this Rx<T> to keep the values in sync. | ||
151 | - /// You can bind multiple sources to update the value. | ||
152 | - /// Closing the subscription will happen automatically when the observer | ||
153 | - /// Widget ([GetX] or [Obx]) gets unmounted from the Widget tree. | ||
154 | - void bindStream(Stream<T> stream) { | ||
155 | - _subscriptions.add(stream.listen((va) => value = va)); | 154 | + /// Closes the subscriptions for this Rx, releasing the resources. |
155 | + void close() { | ||
156 | + for (final subscription in _subscriptions) { | ||
157 | + subscription?.cancel(); | ||
158 | + } | ||
159 | + _subscriptions.clear(); | ||
160 | + subject.close(); | ||
156 | } | 161 | } |
157 | } | 162 | } |
158 | 163 | ||
159 | /// Base Rx class that manages all the stream logic for any Type. | 164 | /// Base Rx class that manages all the stream logic for any Type. |
160 | -abstract class _RxImpl<T> with RxObjectMixin<T> implements RxInterface<T> { | 165 | +abstract class _RxImpl<T> extends RxNotifier<T> with RxObjectMixin<T> { |
161 | _RxImpl(T initial) { | 166 | _RxImpl(T initial) { |
162 | _value = initial; | 167 | _value = initial; |
163 | } | 168 | } |
@@ -7,23 +7,15 @@ part of rx_types; | @@ -7,23 +7,15 @@ part of rx_types; | ||
7 | abstract class RxInterface<T> { | 7 | abstract class RxInterface<T> { |
8 | RxInterface([T initial]); | 8 | RxInterface([T initial]); |
9 | 9 | ||
10 | - GetStream<T> subject; | 10 | + bool get canUpdate; |
11 | 11 | ||
12 | /// Adds a listener to stream | 12 | /// Adds a listener to stream |
13 | void addListener(GetStream<T> rxGetx); | 13 | void addListener(GetStream<T> rxGetx); |
14 | 14 | ||
15 | - bool get canUpdate; | ||
16 | - | ||
17 | - set value(T val); | ||
18 | - | ||
19 | - T get value; | ||
20 | - | ||
21 | - /// Closes the stream | ||
22 | - // FIXME: shouldn't we expose the returned future? | 15 | + /// Close the Rx Variable |
23 | void close(); | 16 | void close(); |
24 | 17 | ||
25 | /// Calls [callback] with current value, when the value changes. | 18 | /// Calls [callback] with current value, when the value changes. |
26 | StreamSubscription<T> listen(void Function(T event) onData, | 19 | StreamSubscription<T> listen(void Function(T event) onData, |
27 | {Function onError, void Function() onDone, bool cancelOnError}); | 20 | {Function onError, void Function() onDone, bool cancelOnError}); |
28 | } | 21 | } |
29 | - |
@@ -2,7 +2,7 @@ part of rx_types; | @@ -2,7 +2,7 @@ part of rx_types; | ||
2 | 2 | ||
3 | /// Create a list similar to `List<T>` | 3 | /// Create a list similar to `List<T>` |
4 | class RxList<E> extends ListMixin<E> | 4 | class RxList<E> extends ListMixin<E> |
5 | - with RxObjectMixin<List<E>> | 5 | + with NotifyManager<List<E>>, RxObjectMixin<List<E>> |
6 | implements RxInterface<List<E>> { | 6 | implements RxInterface<List<E>> { |
7 | RxList([List<E> initial]) { | 7 | RxList([List<E> initial]) { |
8 | _value = initial; | 8 | _value = initial; |
1 | part of rx_types; | 1 | part of rx_types; |
2 | 2 | ||
3 | class RxMap<K, V> extends MapMixin<K, V> | 3 | class RxMap<K, V> extends MapMixin<K, V> |
4 | - with RxObjectMixin<Map<K, V>> | 4 | + with NotifyManager<Map<K, V>>, RxObjectMixin<Map<K, V>> |
5 | implements RxInterface<Map<K, V>> { | 5 | implements RxInterface<Map<K, V>> { |
6 | RxMap([Map<K, V> initial]) { | 6 | RxMap([Map<K, V> initial]) { |
7 | - _value = initial; | 7 | + _value = initial; |
8 | } | 8 | } |
9 | 9 | ||
10 | @override | 10 | @override |
1 | part of rx_types; | 1 | part of rx_types; |
2 | 2 | ||
3 | class RxSet<E> extends SetMixin<E> | 3 | class RxSet<E> extends SetMixin<E> |
4 | - with RxObjectMixin<Set<E>> | 4 | + with NotifyManager<Set<E>>, RxObjectMixin<Set<E>> |
5 | implements RxInterface<Set<E>> { | 5 | implements RxInterface<Set<E>> { |
6 | RxSet([Set<E> initial]) { | 6 | RxSet([Set<E> initial]) { |
7 | if (initial != null) _value = initial; | 7 | if (initial != null) _value = initial; |
@@ -71,8 +71,6 @@ class RxSet<E> extends SetMixin<E> | @@ -71,8 +71,6 @@ class RxSet<E> extends SetMixin<E> | ||
71 | refresh(); | 71 | refresh(); |
72 | } | 72 | } |
73 | 73 | ||
74 | - | ||
75 | - | ||
76 | @override | 74 | @override |
77 | bool add(E value) { | 75 | bool add(E value) { |
78 | final val = _value.add(value); | 76 | final val = _value.add(value); |
@@ -45,7 +45,7 @@ typedef WorkerCallback<T> = Function(T callback); | @@ -45,7 +45,7 @@ typedef WorkerCallback<T> = Function(T callback); | ||
45 | /// ``` | 45 | /// ``` |
46 | Worker ever<T>(RxInterface<T> listener, WorkerCallback<T> callback, | 46 | Worker ever<T>(RxInterface<T> listener, WorkerCallback<T> callback, |
47 | {dynamic condition = true}) { | 47 | {dynamic condition = true}) { |
48 | - StreamSubscription sub = listener.subject.listen((event) { | 48 | + StreamSubscription sub = listener.listen((event) { |
49 | if (_conditional(condition)) callback(event); | 49 | if (_conditional(condition)) callback(event); |
50 | }); | 50 | }); |
51 | return Worker(sub.cancel, '[ever]'); | 51 | return Worker(sub.cancel, '[ever]'); |
@@ -59,7 +59,7 @@ Worker everAll(List<RxInterface> listeners, WorkerCallback callback, | @@ -59,7 +59,7 @@ Worker everAll(List<RxInterface> listeners, WorkerCallback callback, | ||
59 | {dynamic condition = true}) { | 59 | {dynamic condition = true}) { |
60 | final evers = <StreamSubscription>[]; | 60 | final evers = <StreamSubscription>[]; |
61 | for (var i in listeners) { | 61 | for (var i in listeners) { |
62 | - final sub = i.subject.listen((event) { | 62 | + final sub = i.listen((event) { |
63 | if (_conditional(condition)) callback(event); | 63 | if (_conditional(condition)) callback(event); |
64 | }); | 64 | }); |
65 | evers.add(sub); | 65 | evers.add(sub); |
@@ -100,7 +100,7 @@ Worker once<T>(RxInterface<T> listener, WorkerCallback<T> callback, | @@ -100,7 +100,7 @@ Worker once<T>(RxInterface<T> listener, WorkerCallback<T> callback, | ||
100 | {dynamic condition}) { | 100 | {dynamic condition}) { |
101 | Worker ref; | 101 | Worker ref; |
102 | StreamSubscription sub; | 102 | StreamSubscription sub; |
103 | - sub = listener.subject.listen((event) { | 103 | + sub = listener.listen((event) { |
104 | if (!_conditional(condition)) return; | 104 | if (!_conditional(condition)) return; |
105 | ref._disposed = true; | 105 | ref._disposed = true; |
106 | ref._log('called'); | 106 | ref._log('called'); |
@@ -132,7 +132,7 @@ Worker interval<T>(RxInterface<T> listener, WorkerCallback<T> callback, | @@ -132,7 +132,7 @@ Worker interval<T>(RxInterface<T> listener, WorkerCallback<T> callback, | ||
132 | {Duration time = const Duration(seconds: 1), dynamic condition = true}) { | 132 | {Duration time = const Duration(seconds: 1), dynamic condition = true}) { |
133 | var debounceActive = false; | 133 | var debounceActive = false; |
134 | time ??= const Duration(seconds: 1); | 134 | time ??= const Duration(seconds: 1); |
135 | - StreamSubscription sub = listener.subject.listen((event) async { | 135 | + StreamSubscription sub = listener.listen((event) async { |
136 | if (debounceActive || !_conditional(condition)) return; | 136 | if (debounceActive || !_conditional(condition)) return; |
137 | debounceActive = true; | 137 | debounceActive = true; |
138 | await Future.delayed(time); | 138 | await Future.delayed(time); |
@@ -165,7 +165,7 @@ Worker debounce<T>(RxInterface<T> listener, WorkerCallback<T> callback, | @@ -165,7 +165,7 @@ Worker debounce<T>(RxInterface<T> listener, WorkerCallback<T> callback, | ||
165 | {Duration time}) { | 165 | {Duration time}) { |
166 | final _debouncer = | 166 | final _debouncer = |
167 | Debouncer(delay: time ?? const Duration(milliseconds: 800)); | 167 | Debouncer(delay: time ?? const Duration(milliseconds: 800)); |
168 | - StreamSubscription sub = listener.subject.listen((event) { | 168 | + StreamSubscription sub = listener.listen((event) { |
169 | _debouncer(() { | 169 | _debouncer(() { |
170 | callback(event); | 170 | callback(event); |
171 | }); | 171 | }); |
@@ -43,6 +43,9 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | @@ -43,6 +43,9 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | ||
43 | } | 43 | } |
44 | 44 | ||
45 | class GetXState<T extends DisposableInterface> extends State<GetX<T>> { | 45 | class GetXState<T extends DisposableInterface> extends State<GetX<T>> { |
46 | + GetXState() { | ||
47 | + _observer = RxNotifier(); | ||
48 | + } | ||
46 | RxInterface _observer; | 49 | RxInterface _observer; |
47 | T controller; | 50 | T controller; |
48 | bool isCreator = false; | 51 | bool isCreator = false; |
@@ -50,7 +53,6 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -50,7 +53,6 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
50 | 53 | ||
51 | @override | 54 | @override |
52 | void initState() { | 55 | void initState() { |
53 | - _observer = Rx(); | ||
54 | var isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); | 56 | var isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); |
55 | var isRegistered = GetInstance().isRegistered<T>(tag: widget.tag); | 57 | var isRegistered = GetInstance().isRegistered<T>(tag: widget.tag); |
56 | 58 | ||
@@ -77,7 +79,7 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -77,7 +79,7 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
77 | if (widget.global && Get.smartManagement == SmartManagement.onlyBuilder) { | 79 | if (widget.global && Get.smartManagement == SmartManagement.onlyBuilder) { |
78 | controller?.onStart(); | 80 | controller?.onStart(); |
79 | } | 81 | } |
80 | - subs = _observer.subject.listen((data) => setState(() {})); | 82 | + subs = _observer.listen((data) => setState(() {})); |
81 | super.initState(); | 83 | super.initState(); |
82 | } | 84 | } |
83 | 85 |
@@ -24,12 +24,12 @@ class _ObxState extends State<ObxWidget> { | @@ -24,12 +24,12 @@ class _ObxState extends State<ObxWidget> { | ||
24 | StreamSubscription subs; | 24 | StreamSubscription subs; |
25 | 25 | ||
26 | _ObxState() { | 26 | _ObxState() { |
27 | - _observer = Rx(); | 27 | + _observer = RxNotifier(); |
28 | } | 28 | } |
29 | 29 | ||
30 | @override | 30 | @override |
31 | void initState() { | 31 | void initState() { |
32 | - subs = _observer.subject.listen((data) => setState(() {})); | 32 | + subs = _observer.listen((data) => setState(() {})); |
33 | super.initState(); | 33 | super.initState(); |
34 | } | 34 | } |
35 | 35 | ||
@@ -89,9 +89,6 @@ class Obx extends ObxWidget { | @@ -89,9 +89,6 @@ class Obx extends ObxWidget { | ||
89 | /// ), | 89 | /// ), |
90 | /// false.obs, | 90 | /// false.obs, |
91 | /// ), | 91 | /// ), |
92 | - | ||
93 | -// TODO: change T to a proper Rx interface, that includes the accessor | ||
94 | -// for ::value | ||
95 | class ObxValue<T extends RxInterface> extends ObxWidget { | 92 | class ObxValue<T extends RxInterface> extends ObxWidget { |
96 | final Widget Function(T) builder; | 93 | final Widget Function(T) builder; |
97 | final T data; | 94 | final T data; |
@@ -101,3 +98,24 @@ class ObxValue<T extends RxInterface> extends ObxWidget { | @@ -101,3 +98,24 @@ class ObxValue<T extends RxInterface> extends ObxWidget { | ||
101 | @override | 98 | @override |
102 | Widget build() => builder(data); | 99 | Widget build() => builder(data); |
103 | } | 100 | } |
101 | + | ||
102 | +/// Similar to Obx, but manages a local state. | ||
103 | +/// Pass the initial data in constructor. | ||
104 | +/// Useful for simple local states, like toggles, visibility, themes, | ||
105 | +/// button states, etc. | ||
106 | +/// Sample: | ||
107 | +/// ObxValue((data) => Switch( | ||
108 | +/// value: data.value, | ||
109 | +/// onChanged: (flag) => data.value = flag, | ||
110 | +/// ), | ||
111 | +/// false.obs, | ||
112 | +/// ), | ||
113 | +class RxValue<T> extends ObxWidget { | ||
114 | + final Widget Function(T data) builder; | ||
115 | + final Rx<T> data = Rx<T>(); | ||
116 | + | ||
117 | + RxValue(this.builder, {Key key}) : super(key: key); | ||
118 | + | ||
119 | + @override | ||
120 | + Widget build() => builder(data.value); | ||
121 | +} |
@@ -94,7 +94,7 @@ class GetUtils { | @@ -94,7 +94,7 @@ class GetUtils { | ||
94 | 94 | ||
95 | /// Checks if string consist only Alphabet. (No Whitespace) | 95 | /// Checks if string consist only Alphabet. (No Whitespace) |
96 | static bool isAlphabetOnly(String s) => hasMatch(s, r'^[a-zA-Z]+$'); | 96 | static bool isAlphabetOnly(String s) => hasMatch(s, r'^[a-zA-Z]+$'); |
97 | - | 97 | + |
98 | /// Checks if string contains at least one Capital Letter | 98 | /// Checks if string contains at least one Capital Letter |
99 | static bool hasCapitalletter(String s) => hasMatch(s, r'[A-Z]'); | 99 | static bool hasCapitalletter(String s) => hasMatch(s, r'[A-Z]'); |
100 | 100 |
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.15.0 | 3 | +version: 3.16.1 |
4 | homepage: https://github.com/jonataslaw/getx | 4 | homepage: https://github.com/jonataslaw/getx |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment