rxdart_flutter 0.0.1-dev.1 copy "rxdart_flutter: ^0.0.1-dev.1" to clipboard
rxdart_flutter: ^0.0.1-dev.1 copied to clipboard

RxDart Flutter - Flutter Widgets that make it easy to use Streams with Flutter.

RxDart Flutter #

build

RxDart

Build Status codecov Pub Pub Version (including pre-releases) Gitter Flutter website Build Flutter example License Hits

ValueStreamBuilder #

ValueStreamBuilder is a widget similar to StreamBuilder, but works with ValueStream and simplifies the process of rebuilding widgets in response to stream updates. It provides a more streamlined API and performance improvements for working with streams that always have a value and do not emit errors.

Features #

  • Works with ValueStream instead of Stream.
  • Automatically rebuilds the widget when the stream emits new data.
  • Supports optional buildWhen callback for more granular control over rebuild behavior.

Usage #

Basic Example

final valueStream = BehaviorSubject<int>.seeded(0);

ValueStreamBuilder<int>(
  stream: valueStream,
  builder: (context, data) {
    // return widget here based on data
    return Text('Current value: $data');
  },
);

Example with buildWhen

You can provide an optional buildWhen callback to control when the widget should be rebuilt based on changes to the data.

ValueStreamBuilder<int>(
  stream: valueStream,
  buildWhen: (previous, current) {
    // Only rebuild if the current value is different from the previous value
    return previous != current;
  },
  builder: (context, data) {
    return Text('Current value: $data');
  },
);

Parameters #

  • stream: The ValueStream to listen to. The stream must have a value at all times and must not emit errors.
  • builder: A callback that returns the widget to display based on the stream data.
  • buildWhen: An optional callback that determines whether to rebuild the widget based on the previous and current data. Defaults to true (always rebuilds).

Error Handling #

ValueStreamBuilder requires the stream to always have a value and never emit errors. If an error occurs in the stream, it will be displayed using the ErrorWidget.

If the stream has no value when the builder is first called, a ValueStreamHasNoValueError will be thrown. You can handle this by ensuring that the stream is seeded with an initial value or by checking if the stream has a value before using ValueStreamBuilder.

7
likes
0
points
49
downloads

Publisher

unverified uploader

Weekly Downloads

RxDart Flutter - Flutter Widgets that make it easy to use Streams with Flutter.

Repository (GitHub)
View/report issues

Topics

#rxdart #reactive-programming #streams #observables #rx

License

unknown (license)

Dependencies

flutter, rxdart

More

Packages that depend on rxdart_flutter