Cubit has been merged with BLoC in flutter_bloc v6.0.0

What do I mean?

Well, hello again in another exciting article and this time is about a major updates that have been done in the last few weeks and I’ve been busy to write an article or demo about it.

Lest build a simple demo with cubit and bloc

I’ll assume that you already worked with the bloc library before since I’ll not cover it now but you can read my previous article about bloc state management.

Coding

After creating the futter app and setting up all the things we need, let see how I organized the structure of the folders

app folder structure
providers.dart
the providers property that we pass into it a list of BlocProvider we talked about above

Let’s explain the user_cubit and user_state

The user_state contains the states we emit when calling a specific method inside the cubit and here we have a common property called (status) that will hold a String value then passed to the abstracted class.

user_state.dart
user_cubit.dart

The UI

In the UI, we need to build 3 buttons to call each method we wrote earlier in the user_cubit and as shown below

main_view.dart

Testing

Once we click at any button, it will call the method then emit the specified state and widget rebuilt with the new state and data.

AKA The bitByte Guy, Software Developer and Hardware Lover