Flutter Vanilla State Management

This post was originally published on this site

Apium Hub

We are all used when managing a state without any library in Flutter we have to create a StatefulWidget. And that to change its state and update a widget we have to do it using the setState(() => state=newState) method.

However, every time we run setState we are rebuilding all the widgets but due to the efficiency with which Flutter rebuilds them, we hardly notice their cost.

In some cases we can minimize the rebuilt widgets by extracting only the widget we want to update in a StatefulWidget.

But not in all cases this is possible and in those cases this is achieved with the help of ValueNotifier and ValueListenableBuilder.

ValueNotifier

ValueNotifier is a class that extends ChangeNotifier and implements ValueListenable.

In the ChangeNotifier class all the listener management logic is implemented. You may ask yourself, what are listeners? The listeners are a list of callbacks that are executed when

To read the full article click on the 'post' link at the top.