Update about Flutter BLoC Pattern (2022)

Junji Zhi
1 min readJul 31, 2022

--

Since I wrote about Flutter BLoC pattern back in 2019, the Flutter space has changed a lot, so I want to provide an updated view of how things are in 2022.

Flutter office doc has a tutorial about how to manage states. The article does
not mention a word about BLoC, but the implementation is highly similar to the one I implemented: They both rely on ~ChangeNotifier~ as the underlying mechanism to notify changes.

Below is my summary of the noticeable differences between my old approaches and the Flutter official one:

- My CartBloc was using with while their CartModel uses extends
- They use a built-in ChangeNotifierProvider to wrap around the low level
provider usage, so it shortens the code in a way.
- They mention Consumer and provides example and guidance about how to use provider Consumer. And that’s useful!

Overall, I’m glad to see I arrived at an approach that was highly similar to the
one endorsed by Flutter community. Porting the code based on my old approach should not be that hard.

If you are starting to implement any state management in your app (chances are you will), I encourage you to read the official doc and follow their approach instead.

Thanks for your read!

--

--

No responses yet