listenable_stream 2.0.1 copy "listenable_stream: ^2.0.1" to clipboard
listenable_stream: ^2.0.1 copied to clipboard

Convert Listenable (e.g. ChangeNotifier), ValueListenable(e.g. ValueNotifier) to Stream / ValueStream.

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").

Pub Version codecov Flutter Tests GitHub Style Hits

  • ListenableStream<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();

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

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

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).
9
likes
160
points
11.7k
downloads

Publisher

unverified uploader

Weekly Downloads

Convert Listenable (e.g. ChangeNotifier), ValueListenable(e.g. ValueNotifier) to Stream / ValueStream.

Repository (GitHub)
View/report issues

Topics

#rxdart #hoc081098 #reactive-programming #bloc #state-management

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

flutter, rxdart

More

Packages that depend on listenable_stream