Add scoped_listenable
as a dependency in your pubspec.yaml
file.
Provide a Listenable to descendant widgets.
ScopedListenable(
listenable: counterModel,
child: MyApp(),
);
Observe changes in the Listenable provided by an ancestor widget.
ScopedBuilder<CounterModel>(
builder: (context, listenable, child) {
return Text('${listenable.counter}');
},
);
To add multiple ScopedListenables, use ScopedContainer.
ScopedContainer(
container: [
ScopedListenable.from(counterModel),
ScopedListenable.from(settingsModel),
],
child: MyApp(),
);
To obtain Listenable directly, use extension methods.
void initState() {
context.get<CounterModel>().reset();
Widget build(BuildContext context) {
final counterModel = context.watch<CounterModel>();
This is an updated version of scoped_model.
Credits to the original authors and maintainers of the package.