Skip to Content

Cubit

live A reactive state machine that owns a single immutable state value and notifies listeners whenever that state changes. Subclass Cubit and add methods that call Cubit to transition to a new state. Pair with CubitBuilder to rebuild UI subtrees in response to state changes, or expose via Provider for tree-wide access.

Constructor

Cubit

Creates a new cubit with the given initial state.

ParameterDescription
initialStateThe initial state value.

Properties

State

The current state of this cubit.

Methods

AddListener

Registers a callback that is invoked whenever the state changes.

ParameterDescription
listenerThe callback to invoke. Receives the new state value.

Dispose

Disposes this cubit, clearing all listeners and preventing further state transitions.

Emit

Transitions to , notifying all listeners. If is equal to the current state the call is a no-op and no listeners are invoked. Equality is determined via EqualityComparer

ParameterDescription
newStateThe state to transition to.

OnDispose

Called when this cubit is disposed. Override to release additional resources.

RemoveListener

Removes a previously registered listener. Does nothing if the listener is not found.

ParameterDescription
listenerThe callback to remove.
Last updated on