Skip to content

crizant/multi_listenable_builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages