chapter eight

8 Flutter State Management

 

In this chapter:

  • StatefulWidget and State object
  • Widget tree vs Element tree
  • State object lifecycle
  • InheritedWidget
  • Intro to Streams and Async Dart
  • Bloc state management architecture

This chapter is going to be a ton of fun, for two reasons: First, there isn’t one approach state management (in Flutter or elsewhere). There are many different state management patterns, and all developers have opinions about each of them. And second, developers (including myself) are… passionate… about their opinions.

With that in mind, I won’t be able to do a deep dive on every pattern that’s popular right now. I thought a lot about which patterns I should cover, and I came up with this two-pronged litmus test to decide:

  1. Will it help you expand your Flutter and Dart skills specifically?
  2. Is it un-opinionated enough that it’s concepts can be applied elsewhere?

8.1  Deep Dive into StatefulWidget

8.1.1  The Widget Tree and the Element Tree

8.1.2  The StatefulWidget Lifecycle and When to Do What

8.2  Pure Flutter state management: The InheritedWidget

8.2.1  Creating a Central Store wth an InheritedWidget + StatefulWidget team

8.2.2  The 'inheritFromWidgetOfExactType' and 'of' methods

8.2.3  Use the of method to lift state up

8.2.4  State management patterns beyond Flutter

8.3  Blocs: Business Logic Components

8.3.1  Blocs. How do they work?

8.3.2  Implementing the Bloc architecture

8.3.3  Intro to Streams and Async Dart

8.3.4  Implementing Streams in the CartBloc

8.4  Summary