Last updated:
0 purchases
inherited stream
Inherited Stream #
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,
ValueStream<double> stream,
Widget child,
}) : super(key: key, stream: stream, child: child);
static double of(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<ProgressModel>()
.stream
.value;
}
}
copied to clipboard
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()),
),
);
}
}
copied to clipboard
Register Dependant(s) #
class Progress extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CircularProgressIndicator(value: ProgressModel.of(context));
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.