Last updated:
0 purchases
listenable stream
listenable_stream #
Convert Flutter's Listenable (e.g. ChangeNotifier) to Stream.
Convert Flutter's ValueListenable (e.g. ValueNotifier) to ValueStream (incl. "replay" and "not replay").
✅ Listenable ▶ Stream<Listenable>
✅ ValueListenable<T> ▶ ValueStream<T>
Usage #
Listenable.toStream() #
final ChangeNotifier changeNotifier = ChangeNotifier();
final Stream<ChangeNotifier> stream = changeNotifier.toStream();
stream.listen(print); // prints Instance of 'ChangeNotifier', Instance of 'ChangeNotifier'
changeNotifier.notifyListeners();
changeNotifier.notifyListeners();
copied to clipboard
ValueListenable.toValueStream() #
final ValueNotifier<int> valueNotifier = ValueNotifier(0);
final ValueListenableStream<int> stream = valueNotifier.toValueStream();
stream.listen(print); // prints 1, 2
valueNotifier.value = 1;
valueNotifier.value = 2;
print(stream.value); // prints 2
copied to clipboard
ValueListenable.toValueStream(replayValue: true) #
final ValueNotifier<int> valueNotifier = ValueNotifier(0);
final ValueListenableStream<int> stream = valueNotifier.toValueStream(replayValue: true);
stream.listen(print); // prints 0, 1, 2
valueNotifier.value = 1;
valueNotifier.value = 2;
print(stream.value); // prints 2
copied to clipboard
Note #
All returned Stream is single-subscription Stream (ie. it can only be listened once) and does not emits any errors.
ValueListenableStream always has value (ie. has no error).
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.