Events, States, and the Cubit-vs-Bloc Decision
Decide between Cubit and Bloc and design clean event-to-state transformations.
Two Tools, One Family
The flutter_bloc package ships two state-management primitives: Cubit and Bloc. Both extend the same base class and both emit a stream of states to your UI.
- Cubit exposes plain methods you call directly (e.g.
increment()). - Bloc reacts to events you add (e.g.
add(IncrementPressed())) and maps them to states.
This lesson teaches you how each one transforms input into State, and how to pick the right one for a given feature.
Cubit: Methods to States
A Cubit is the simpler primitive. You extend Cubit<T>, pass an initial state to super(...), and call emit(newState) inside methods to push a new state to listeners.
There is no event object and no mapping layer. The method is the API surface.
import 'package:flutter_bloc/flutter_bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
void decrement() => emit(state - 1);
void reset() => emit(0);
}All lessons in this course
- Events, States, and the Cubit-vs-Bloc Decision
- Stream Transformers and Event Debouncing in BLoC
- Persisting State with HydratedBloc
- Testing BLoCs with bloc_test and Mocktail