multi_listenable_builder 1.0.0 copy "multi_listenable_builder: ^1.0.0" to clipboard
multi_listenable_builder: ^1.0.0 copied to clipboard

A widget builder whose content stays synced with one or more Listenables.

multi_listenable_builder #

A widget builder whose content stays synced with one or more Listenables.

What is this? #

Many of us flutter developers use ChangeNotifier for state management, they may use ListenableBuilder to keep their widgets in sync with the model, but it's a mess when they need to listen to more than one Listenables.

Example #

Let's say you have a model of ChangeNotifier like this:

class CounterModel extends ChangeNotifier {
  int _count = 0;

  void increment() {
    _count++;
    notifyListeners();
  }

  int get count => _count;
}

Then in the build method of your widget:

MultiListenableBuilder(
  // supply the instance of `ChangeNotifier` model,
  // whether you get it from the build context or anywhere
  notifiers: [_counterModel],
  // this builder function will be executed,
  // once the `ChangeNotifier` model is updated
  builder: (BuildContext context, _) {
    return Text(
      '${_counterModel.count}',
      style: Theme.of(context).textTheme.headlineMedium,
    );
  },
)

Contributions #

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue. If you fixed a bug or implemented a feature, please send a pull request.

0
likes
160
pub points
46%
popularity

Publisher

unverified uploader

A widget builder whose content stays synced with one or more Listenables.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on multi_listenable_builder