What's the difference between Bloc and Cubit?
Short Answer
Cubit is a simplified version of Bloc — you call methods directly to emit new states, instead of dispatching Events that get mapped to states — trading some of Bloc's structure and traceability for less boilerplate.
A full Bloc requires defining Event classes and an on<Event>() handler mapping each event to emitted states — verbose, but it creates a clear, replayable log of exactly what triggered each state change. Cubit skips the Event layer entirely: you call a method like counterCubit.increment(), which directly calls emit(state + 1) inside its body.
The practical tradeoff: Cubit is faster to write and easier to understand for simple state, but you lose the explicit, named 'what caused this' record that Bloc's events provide — which matters more as business logic gets complex or when you want event-replay debugging.
Code Example
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}
// Usage
context.read<CounterCubit>().increment();Common Mistakes
- ×Choosing Bloc for a trivial toggle/counter where Cubit's simplicity would suffice.
- ×Choosing Cubit for genuinely complex business logic where Bloc's explicit events would make the code far easier to trace and test.