scoped_listenable 2.0.0 copy "scoped_listenable: ^2.0.0" to clipboard
scoped_listenable: ^2.0.0 copied to clipboard

Provides a Listenable to descendant widgets.

Getting started #

Add scoped_listenable as a dependency in your pubspec.yaml file.

Usage #

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}');
  },
);

Advanced #

To add multiple ScopedListenables, use ScopedListenable.merge.

ScopedListenable.merge(
  listenables: [
    ScopedListenable.from(counterModel),
    // Or
    counterModel.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>();

Additional information #

This is an updated version of scoped_model. Credits to the original authors and maintainers.

0
likes
130
points
177
downloads

Publisher

unverified uploader

Weekly Downloads

Provides a Listenable to descendant widgets.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on scoped_listenable