Showing
1 changed file
with
19 additions
and
0 deletions
| @@ -18,4 +18,23 @@ abstract class RxInterface<T> { | @@ -18,4 +18,23 @@ abstract class RxInterface<T> { | ||
| 18 | /// Calls [callback] with current value, when the value changes. | 18 | /// Calls [callback] with current value, when the value changes. | 
| 19 | StreamSubscription<T> listen(void Function(T event) onData, | 19 | StreamSubscription<T> listen(void Function(T event) onData, | 
| 20 | {Function? onError, void Function()? onDone, bool? cancelOnError}); | 20 | {Function? onError, void Function()? onDone, bool? cancelOnError}); | 
| 21 | + | ||
| 22 | + /// Avoids an unsafe usage of the `proxy` | ||
| 23 | + static T notifyChildren<T>(RxNotifier observer, ValueGetter<T> builder) { | ||
| 24 | + final _observer = RxInterface.proxy; | ||
| 25 | + RxInterface.proxy = observer; | ||
| 26 | + final result = builder(); | ||
| 27 | + if (!observer.canUpdate) { | ||
| 28 | + throw """ | ||
| 29 | + [Get] the improper use of a GetX has been detected. | ||
| 30 | + You should only use GetX or Obx for the specific widget that will be updated. | ||
| 31 | + If you are seeing this error, you probably did not insert any observable variables into GetX/Obx | ||
| 32 | + or insert them outside the scope that GetX considers suitable for an update | ||
| 33 | + (example: GetX => HeavyWidget => variableObservable). | ||
| 34 | + If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX. | ||
| 35 | + """; | ||
| 36 | + } | ||
| 37 | + RxInterface.proxy = _observer; | ||
| 38 | + return result; | ||
| 39 | + } | ||
| 21 | } | 40 | } | 
- 
Please register or login to post a comment