ABSTRACT

In this chapter, you will learn to implement the state-management solution for CounterApp with the help of the Provider package and ChangeNotifier class. This solution helps solve state-management problems at the application level. In this implementation, the homepage is a stateless widget since it's not managing the state directly but through ChangeNotifier. The Provider package is facilitating the state to pass along the children widgets. The Provider package uses InheritedWidget under the hood. It is like a wrapper to make code more reusable and easier to use. The InheritedWidget is a base class for all widgets. It efficiently propagates information down its widget tree. The provider(s) are placed above the widget(s) they're supposed to provide data. In this chapter, you will add Provider package as a dependency to the Flutter project. You will learn to use ChangeNotifierProvider widget to access the ChangeNotifier class. Finally, you will learn to create a custom ChangeNotifier class to learn manage counter states in CounterApp.