ABSTRACT

In the previous chapter (Chapter 16: Introduction to State Management), we discussed managing the widget's state using the stateful widget. You learned to manage state in StatefulWidget using the `setState()` method. We saw that the interface is rebuilt every time the counter was updated inside the `setState()` method. In this chapter, we'll look into one of the solutions to avoid rebuilding the entire widget tree of StatefulWidget. We will learn how to use ValueNotifier (ValueNotifier<T> class) to only rebuild the Text widget displaying the counter value rather than rebuilding the entire widget tree. The widgets subscribed to the ValueNotifier get notified whenever its value is updated. In this chapter, you will also learn to implement the state-management solution with ValueNotifier, ValueListenable, ValueListenableBuilder widget. Using ValueNotifier implementation for managing state helps to reduce the number of times a widget is being rebuilt. In the next chapter, you will get introduced to another approach for state management using the `provider` package.