stream_listenable 1.0.0 copy "stream_listenable: ^1.0.0" to clipboard
stream_listenable: ^1.0.0 copied to clipboard

Bridge Dart Streams into Flutter's Listenable/ValueListenable interfaces. Lazily subscribes and auto-cancels.

stream_listenable #

Bridge Dart Streams into Flutter's Listenable / ValueListenable interfaces.

Wraps any Stream<T> so it can be used with ListenableBuilder, ValueListenableBuilder, AnimatedBuilder, and any other widget or API that accepts a Listenable.

Features #

  • StreamListenable<T> — implements Listenable. Notifies listeners on every stream emission.
  • StreamValueListenable<T> — implements ValueListenable<T>. Tracks the latest value and notifies on changes.
  • Extension methodsstream.asListenable() and stream.asValueListenable() for concise usage.
  • Lazy subscription — subscribes when the first listener is added, cancels when the last is removed.

Getting started #

dependencies:
  stream_listenable: ^1.0.0

Usage #

As a Listenable #

final listenable = myStream.asListenable();

ListenableBuilder(
  listenable: listenable,
  builder: (context, child) {
    // Rebuilds on every stream emission
    return Text('Stream emitted');
  },
);

As a ValueListenable #

final valueListenable = myStream.asValueListenable(initialValue: 0);

ValueListenableBuilder<int>(
  valueListenable: valueListenable,
  builder: (context, value, child) {
    return Text('Value: $value');
  },
);

Options #

// Notify listeners on stream errors and completion
StreamListenable(myStream, notifyOnError: true, notifyOnDone: true);

// Notify even when the same value is emitted consecutively
StreamValueListenable(myStream, initialValue: 0, notifyOnSameValue: true);

Additional information #

0
likes
160
points
8
downloads

Documentation

API reference

Publisher

verified publisherjacopoguzzo.dev

Weekly Downloads

Bridge Dart Streams into Flutter's Listenable/ValueListenable interfaces. Lazily subscribes and auto-cancels.

Repository (GitHub)
View/report issues

Topics

#stream #listenable #valuelistenable #changenotifier

License

MIT (license)

Dependencies

flutter

More

Packages that depend on stream_listenable