stream_with_value 0.1.1 copy "stream_with_value: ^0.1.1" to clipboard
stream_with_value: ^0.1.1 copied to clipboard

outdated

An encapsulation of a Stream and a single value.

stream_with_value #

About #

The package provides the implementation of StreamWithValue that wraps a Stream and keeps the latest value that was received from it.

StreamWithLatestValue - implementation that wraps a Stream and keeps the latest value that was received from it. The value will not be tracked if there are no listeners on updates.

PushStreamWithValue - StreamWithValue implementation that creates a Stream from subsequent calls to add. This way, value is always set to the latest value that has been added, regardless of whether the updates are listened to (in contrast to StreamWithLatestValue).

How to use #

  1. Add stream_with_value to your pubspec.yaml:
dependencies:
  stream_with_value: ^0.1.1
  1. Create StreamWithLatestValue
StreamController<int> _yourStreamController = StreamController<int>();
StreamWithLatestValue<int>  _streamWithValue =
        StreamWithLatestValue<int>.withInitialValue(_yourStreamController.stream, initialValue: 0);

  1. You can add new value to the stream using StreamController.
_yourStreamController.add(5);
  1. To get updates on the UI you can use StreamBuilderWithValue or DataStreamWithValueBuilder widgets:
 StreamBuilderWithValue<int>(
    streamWithValue: _streamWithValue,
    builder: (BuildContext context, AsyncSnapshot snapshot) {
      return (snapshot.hasData)
        ? Text(
            '${snapshot.data ?? 0}',
            style: Theme.of(context).textTheme.headline4,
          )
        : CircularProgressIndicator();
    },
 )

For more examples, please have a look at the example project.

4
likes
0
pub points
57%
popularity

Publisher

verified publisherfutureware.dev

An encapsulation of a Stream and a single value.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on stream_with_value