Flutter Intermediate Chapter 7 of 20
Built-in State Management
Learn Flutter state management without packages: setState, ValueNotifier, ChangeNotifier, InheritedWidget, InheritedNotifier, InheritedModel and builders.
State is any data that can change while the app runs: a counter, the items in a cart, whether the user is logged in. State management is how you store that data and rebuild the right widgets when it changes.
Flutter ships with everything you need to do this, with no packages at all. This chapter teaches the nine built-in tools, from the simplest (setState) to the ones that power packages such as Provider. Learn these first: every package in the next chapter is built on top of them.
Lessons in this chapter
- Flutter State Management Without Packages: All 9 Built-in ToolsA simple map of Flutter's 9 built-in state management tools, from setState and ValueNotifier to InheritedModel and AnimatedBuilder, with runnable examples.
- State in Flutter: setState and Lifting State UpUnderstand state in Flutter: ephemeral versus app state, how setState works, lifting state up to share it, and passing callbacks down.
- ValueNotifier and ChangeNotifier in FlutterManage state in Flutter without packages using ValueNotifier, ChangeNotifier, ValueListenableBuilder and ListenableBuilder.
- ListenableBuilder and AnimatedBuilder in Flutter: Rebuild Only What ChangesUse ListenableBuilder with ChangeNotifier and AnimatedBuilder with animations to rebuild only part of the screen. Easy runnable Flutter examples.
- InheritedWidget in FlutterLearn how InheritedWidget shares data down the widget tree in Flutter, how of(context) works, and why Provider is built on it.
- InheritedNotifier in Flutter: Share a ChangeNotifier Down the TreeLearn InheritedNotifier with an easy example: share a ChangeNotifier with every screen and rebuild only the widgets that use it, with no package.
- InheritedModel in Flutter: Rebuild Only Widgets That Use Changed DataLearn InheritedModel with a simple example: share one model and let each widget depend on only the part it uses, using aspects and updateShouldNotifyDependent.
- StreamController + StreamBuilder and FutureBuilder for State in FlutterManage Flutter state with streams and futures: StreamController with StreamBuilder for live values and FutureBuilder for async results. Runnable code.