Cubit: Simple State Management in Flutter

A Cubit is a simple state manager that exposes functions to directly trigger state changes. It's ideal for managing local UI state, like a counter or form data, without the complexity of events. The footgun is expecting state to update synchronously.
Why it exists
State management in reactive frameworks can be complex. Sometimes you just need to manage a simple piece of state for a widget without the overhead of a full event-based system. Cubit was created as a simpler, more direct subset of the Bloc pattern for these common cases.
The mental model
Think of a Cubit as a specialized controller for a single piece of state. It holds the current state (e.g., the number 5) and exposes plain methods you can call (e.g., increment()). When a method is called, the Cubit computes the next state and broadcasts it to any part of the UI that is listening. It's a direct "call a function, get a new state" model.
How it works
You create a class that extends Cubit<StateType>, providing an initial state in the constructor. For example, class CounterCubit extends Cubit<int> { CounterCubit() : super(0); }. Inside this class, you define public methods that change the state. These methods use the built-in emit() function to push a new state value onto the Cubit's state stream. The state itself is a Stream, a sequence of asynchronous data that UI widgets like BlocBuilder can subscribe to and rebuild upon receiving new data.
When to use it
Use Cubit for simple, localized state management. It's perfect for managing the state of a counter, tracking the selected item in a filter, handling form inputs, or toggling a loading spinner. If your logic can be expressed as "when this function is called, emit this new state," Cubit is a great fit due to its simplicity.
When not to use it
Avoid Cubit when state logic is complex and benefits from being traceable. If you need to know why a state change occurred (e.g., was it UserTappedButtonEvent or DataLoadedEvent?), a full Bloc with its event-driven architecture is a better choice. Cubit functions are direct and imperative; they don't carry the semantic information that events do.
One canonical example
A simple counter Cubit exposes two methods, increment and decrement. Calling increment() calls emit(state + 1), which broadcasts the new integer value to all listeners.
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);void increment() => emit(state + 1);
void decrement() => emit(state - 1);
}A UI widget would then listen to an instance of this Cubit and rebuild itself whenever the integer state changes.
Interview question
Which scenario best describes an ideal use case for Cubit in Flutter?
- a.Implementing a feature that requires complex business logic to determine the next state based on various event types.
- b.Ensuring that UI rebuilds happen synchronously and immediately after any state-modifying function is invoked.
- c.Handling localized UI state updates triggered by direct method calls, like a counter or form input.Correct
- d.Managing application state where the exact sequence of user actions leading to a state change must be preserved.
Why? this is the answer
Cubit is designed for simple, localized state management where direct function calls trigger state changes, as stated in the card. Option B is incorrect because Cubit's state updates are asynchronous, delivered via a Stream, not synchronously.
Just read this? Test yourself on what you have been reading.
Read the original → bloclibrary.dev
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.
See open roles