Store<TState extends Object?> class
abstract
Base class for feature stores with reactive state.
Subclass to hold the state of a feature slice plus the Tasks that mutate it. Stores participate in two orthogonal mechanisms:
- Reactive reads — reading state inside a reaction-tracked
scope (a
StateObserverbody, a port handler) auto-subscribes the enclosing reaction, so writes automatically invalidate it. - Imperative subscribers — subscribe registers a classic
void Function(prev, next)listener for side-effect style integration.
class UserStore extends Store<UserState> {
UserStore() : super(state: const UserState());
late final loadProfile = createTask(
fn: (String userId) async => /* ... */,
strategy: .once,
);
void logout() => update((s) => s.copyWith(user: null));
}
Lifecycle — a store constructed inside a feature's stores
factory is auto-registered with that feature via zone tracking and
disposed when the container tears the feature down. Stores
constructed outside a stores factory (e.g. in tests, or standalone
Dart utilities) are not registered; the owner is responsible for
calling dispose.
Constructors
- Store({required TState state})
-
Creates a store initialised with
state. If this constructor runs inside aStore.trackscope (i.e. inside a feature'sstoresfactory) the instance is automatically collected into the active store map. Duplicate registrations — two Stores of the same runtime type in one feature — throw FeatureConfigurationError before construction completes.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state ↔ TState
-
Current state snapshot.
getter/setter pair
Methods
-
createTask<
TParams extends Object?, TResult extends Object?, TError extends Object?> ({required TaskFn< TParams, TResult, TError> fn, TaskStrategy strategy = TaskStrategy.queue, Duration? autoReset}) → Task<TParams, TResult, TError> -
Creates a parameterised async Task with an observable state
machine (
TaskIdle → TaskPending → TaskDone|TaskFailed). -
createVoidTask<
TResult extends Object?, TError extends Object?> ({required Future< TResult> fn(), TaskStrategy strategy = TaskStrategy.queue, Duration? autoReset}) → VoidTask<TResult, TError> -
Creates a no-parameter VoidTask. Callers invoke it with
task()— nonullargument required — and compile-time safety is preserved for parameterised tasks created via createTask. -
dispose(
) → void -
Tears down the store: disposes its
State(detaches every subscriber and the reactive atom), disposes every owned Task (rejecting in-flight calls with TaskError), and clears the internal task list. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
subscribe(
StateChangeListener< TState> listener, {bool fireImmediately = false}) → StateListenerDisposer -
Subscribes
listenerto state transitions.listenerfires synchronously on every write wherenewState != currentState; equality-suppressed writes don't emit. -
toString(
) → String -
A string representation of this object.
inherited
-
update(
StateUpdateCallback< TState> callback) → void -
Functional state update — applies
callbackto the current value and writes the result.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited