First thing you need to know about BLoC, it’s a state management system that works with states and events.
With BLoC you need to trigger an event and for that related event you should emit a state.
In general events pass data from UI to the shared memory of BLoC or Flutter. Then using state you can access them through the app.
Then how does Cubit work?
First thing you need to know, Cubit is subset is BLoC, it means part of BLoC.
In fact based on my understanding of BLoC and Cubit, they are same but Cubit becomes easier.
Then what makes it easy?
Cubit takes away event triggering. In Cubit, instead of triggering events, you call methods. Because most new Flutter programmer might be familiar with method calling.
This make makes it easier to understand.
Then what other things that make them similar?
Similarities
- Both inject BLoC or Cubit using BlocProvider
- Both can use MultiBlocProvider
- Both can use BlocProvider.of<BLoCOrCubitName>(context) to trigger events or call method
- Both can use BlocProvider.of<BLoCorCubitName>(context).state to access the state object
- Both uses BlocBuilder widgets to access bloc and state in the build method
- Both can utilize so called emit() function
- They both other Hydrated storage for storing data
Cubit and BLoC combine