Sparround

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 call emit(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.

CriterionCubitBloc
Amount of boilerplateLow — just methodsHigher — event classes plus handlers
Event historyNoYes — every event is traceable
Event stream control (debounce, throttle)ManualBuilt in via `transformer`
When to chooseSimple to moderate stateAudit 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