BLoC and Cubit
BLoC (Business Logic Component) manages state through a stream model: events go in, states come out. The UI only dispatches events and listens to states, so business logic is fully separated.
The package offers two levels:
- `Cubit` — the simplified form: no events, just methods (
increment()) that callemit(newState) - `Bloc` — the full form: every change arrives as an event and an
on<Event>handler emits states
A Cubit is enough most of the time. Bloc earns its cost when you need an event history, control over event ordering (debouncing, for example), or auditability.
| Criterion | Cubit | Bloc |
|---|---|---|
| Amount of boilerplate | Low — just methods | Higher — event classes plus handlers |
| Event history | No | Yes — every event is traceable |
| Event stream control (debounce, throttle) | Manual | Built in via `transformer` |
| When to choose | Simple to moderate state | Audit trails, complex flows, large teams |
Interview tip. What is most expected in a BLoC question is why you chose it. Strong arguments: business logic is fully separated from the UI and testable without Flutter; state transitions are traceable (a BlocObserver logs every one); and in a large team the enforced structure keeps code uniform. A weak argument is "it is popular". Name the downside too — the boilerplate is a real cost.
📚 Sources and documentation
- flutter_bloc packageofficialpub.dev
- BLoC library documentationbloclibrary.dev
Covers choosing between Cubit and Bloc, and how to test both.
- State management optionsofficialdocs.flutter.dev