inherited_stream 2.0.0-nullsafety.0 copy "inherited_stream: ^2.0.0-nullsafety.0" to clipboard
inherited_stream: ^2.0.0-nullsafety.0 copied to clipboard

An inherited widget for Streams, which updates its dependencies when the stream emits data.

Inherited Stream #

Pub build coverage License: MIT

An InheritedWidget for Streams, which updates its dependencies when the Stream emits.

Usage #

Create an InheritedStream #

class ProgressModel extends InheritedStream<ValueStream<double>> {
  const ProgressModel({
    Key? key,
    required ValueStream<double> stream,
    required Widget child,
  }) : super(key: key, stream: stream, child: child);

  static double of(BuildContext context) {
    return context
        .dependOnInheritedWidgetOfExactType<ProgressModel>()!
        .stream
        .value!;
  }
}

Insert into the Widget Tree #

class _MyState extends State<MyPage> {
  final _subject = BehaviorSubject<double>.seeded(0.0);

  @override
  void dispose() {
    _subject.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ProgressModel(
        stream: _subject.stream,
        child: Progress(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => _subject.add(Random.nextDouble()),
      ),
    );
  }
}

Register Dependant(s) #

class Progress extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CircularProgressIndicator(value: ProgressModel.of(context));
  }
}
5
likes
140
pub points
45%
popularity

Publisher

verified publisherfelangel.dev

An inherited widget for Streams, which updates its dependencies when the stream emits data.

Repository (GitHub)
View/report issues
Contributing

Documentation

Documentation
API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on inherited_stream