Does The Bloc Pattern Include State Management?
Solution 1
When implementing the Bloc pattern, is it that you already implemented state management?
Yes indeed.
Does this (in most cases) mean that I do not need to use another tool like Redux or Provider?
You can use them, but personally, I see no need when I already use BLoC and would not mix them.
Solution 2
Yes bloc itself is a state management tool in flutter and there is no need to use any other state management tools along with it. Though it can be done but try to use single state management for whole app so that mismatch doesnot happen . Also Bloc makes sure to preserve the state and update it when necessary. That is what state management is !
Jay
Updated on December 19, 2022Comments
-
Jay over 1 year
This may be a noob question but I am new to Flutter. Hearing all those keywords: "State Management, Provider, Redux, MVVM and Bloc", I get a little bit confused.
When implementing the Bloc pattern, is it that you already implemented state management? Does this (in most cases) mean that I do not need to use another tool like Redux or Provider? To get a better idea, I am going to build a mobile webshop using Flutter and the Woocommerce package.
If I understand correctly with the Bloc pattern you have the follow:
- UI screen (view)
- BLOC (ViewModel, including functions such as getting data or updating data or deleting data)
- Repository (Get's data from an API)
- Network Provider (the api itself)
If it's not complete, feel free to add an extra explanation.
Hope anyone has clear answers!
Cheers
-
Jay about 2 yearsAah thanks. this cleared up the confusion
-
Jay about 2 yearsAha thanks! This cleared the confusion I had! What is Single State Management?
-
Jay about 2 yearsDoes this also mean I do not have to use Cubit? Because Cutbit is also a state management tool right? Or am I wrong?
-
nvoigt about 2 yearsA Cubit is a simplified BLoC, for when your state you want to manage is actually just a simple single datatype, like a single int or a single enum value. For example, your whole program state is probably managed by one or more BLoCs, while the part of the state that determines whether your app is running is light mode or dark mode is just a Cubit because there is no big logic or complex data involved.
-
Jay about 2 yearsAha so you can mix BLoC with Cubit (for the small things like you mentioned). Can you name an example of when to use BLoC? For example I want to make a webshop app, I should use BLoC right?
-
nvoigt about 2 yearsYou can (and will) have multiple BLoCs and Cubits in any bigger application, because you have multiple layers of logic and state. For example one BLoC could have the state and logic for the process of a user being logged in or not. Another might have the logic for buying stuff (only reachable if you are logged in). Another might have the simple switch of light- or darkmode of the app. Another might handle the not simple, but not exactly complex logic of switching languages. Logging in is a tutorial for BLoC, while the simple switch of lightmode/darkmode is a perfect exemple for a Cubit.
-
Jay about 2 yearsHmm okay, I think that is clear! Thanks for the answer. There are so many new terms and it is a bit confusing for me but your answer helped me (and we did not even talk about Redux and Provider hahah). Thanks for the answer :)
-
akdev about 2 yearsIt is when you are updating single state only based on an event or trigger. Only one state is updated at a time.