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 ScopedListenable.merge.
ScopedListenable.merge(
listenables: [
counterModel.scoped(),
settingsModel.scoped(),
],
child: MyApp(),
);To obtain Listenable directly, use extension methods.
void initState() {
context.read<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.