flutter_operations library

Type-safe async & stream state management for Flutter powered by sealed classes, exhaustive pattern matching, and cached data. No more juggling isLoading, error, and data fields.

Execution and lifecycle adapters:

All expose OperationState snapshots: idle, loading, success, and error.

Classes

AllTransitions<T>
All destinations available through an OperationState reference.
AsyncOperation<T>
Owns the state and lifecycle of one asynchronous operation.
ErrorOperation<T>
Represents a failed operation with error details. Can optionally retain cached data from a previous successful operation.
FromError<T>
Destinations available through an ErrorOperation reference.
FromIdle<T>
Destinations available through an IdleOperation reference.
FromLoading<T>
Destinations available through a LoadingOperation reference.
FromSuccess<T>
Destinations available through a SuccessOperation reference.
IdleOperation<T>
Represents an idle operation that is ready but not currently loading. Can optionally carry cached data from a previous successful operation.
LoadingOperation<T>
Represents an operation that is currently in progress. Can optionally carry cached data from a previous successful operation.
Operation<T>
Shared state publication for asynchronous and stream execution engines.
OperationState<T>
Represents the state of an asynchronous operation.
StreamOperation<T>
Owns one stream subscription and its operation state.
SuccessOperation<T>
Represents a successfully completed operation with associated data.

Enums

AsyncOperationConcurrency
Defines how AsyncOperation handles a call made while one is running.

Mixins

AsyncOperationMixin<T>
Adds one asynchronous operation to any host object.
AsyncOperationStateMixin<T, K extends StatefulWidget>
Adds one asynchronous operation to a Flutter State.
StreamOperationMixin<T>
Adds one stream operation to an external host.
StreamOperationStateMixin<T, K extends StatefulWidget>
Widget lifecycle adapter for StreamOperation.

Extensions

ErrorTransitions on ErrorOperation<T>
Transitions from error to loading, idle, or success.
IdleTransitions on IdleOperation<T>
Transitions from idle to loading, success, or error.
LoadingTransitions on LoadingOperation<T>
Transitions from loading to idle, success, or error.
OperationTransitions on OperationState<T>
Exposes all destinations when the receiver is an OperationState.
SuccessTransitions on SuccessOperation<T>
Transitions from success to loading, idle, or error.

Typedefs

AsyncOperationWork<T> = FutureOr<T> Function()
Work executed by an AsyncOperation.
OperationChanged<T> = void Function(OperationState<T> previous, OperationState<T> next)
Called immediately after an unequal operation state is assigned.
OperationErrorCallback = void Function(Object error, StackTrace stackTrace, {String? message})
Called when an operation publishes an error.
OperationErrorMessage = String Function(Object error, StackTrace stackTrace)
Converts an error into the message stored in an error snapshot.
StreamOperationSource<T> = Stream<T> Function()
Creates a fresh source for each StreamOperation.listen call.