Fix to rx.trigger so that it checks for previous send to stream by set value
Showing
1 changed file
with
4 additions
and
2 deletions
| @@ -67,6 +67,7 @@ mixin RxObjectMixin<T> on NotifyManager<T> { | @@ -67,6 +67,7 @@ mixin RxObjectMixin<T> on NotifyManager<T> { | ||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | bool firstRebuild = true; | 69 | bool firstRebuild = true; |
| 70 | + bool sentToStream = false; | ||
| 70 | 71 | ||
| 71 | /// Same as `toString()` but using a getter. | 72 | /// Same as `toString()` but using a getter. |
| 72 | String get string => value.toString(); | 73 | String get string => value.toString(); |
| @@ -96,10 +97,11 @@ mixin RxObjectMixin<T> on NotifyManager<T> { | @@ -96,10 +97,11 @@ mixin RxObjectMixin<T> on NotifyManager<T> { | ||
| 96 | /// Widget, only if it's different from the previous value. | 97 | /// Widget, only if it's different from the previous value. |
| 97 | set value(T val) { | 98 | set value(T val) { |
| 98 | if (subject.isClosed) return; | 99 | if (subject.isClosed) return; |
| 100 | + sentToStream = false; | ||
| 99 | if (_value == val && !firstRebuild) return; | 101 | if (_value == val && !firstRebuild) return; |
| 100 | firstRebuild = false; | 102 | firstRebuild = false; |
| 101 | _value = val; | 103 | _value = val; |
| 102 | - | 104 | + sentToStream = true; |
| 103 | subject.add(_value); | 105 | subject.add(_value); |
| 104 | } | 106 | } |
| 105 | 107 | ||
| @@ -254,7 +256,7 @@ abstract class _RxImpl<T> extends RxNotifier<T> with RxObjectMixin<T> { | @@ -254,7 +256,7 @@ abstract class _RxImpl<T> extends RxNotifier<T> with RxObjectMixin<T> { | ||
| 254 | value = v; | 256 | value = v; |
| 255 | // If it's not the first rebuild, the listeners have been called already | 257 | // If it's not the first rebuild, the listeners have been called already |
| 256 | // So we won't call them again. | 258 | // So we won't call them again. |
| 257 | - if (!firstRebuild) { | 259 | + if (!firstRebuild && !sentToStream) { |
| 258 | subject.add(v); | 260 | subject.add(v); |
| 259 | } | 261 | } |
| 260 | } | 262 | } |
-
Please register or login to post a comment