better_effect_flutter library
Flutter MVVM integration for better_effect.
The Dart-only core is re-exported so applications normally need one import:
import 'package:better_effect_flutter/better_effect_flutter.dart';
Classes
- AutoInjectorBackend
-
The default ResolverBackend, powered by
package:auto_injector. - BetterEffectBootstrap
- Declaratively starts an application-owned Runtime inside Flutter.
- BetterEffectFeatureScope
- Owns one child Runtime for a Flutter feature subtree.
- BetterEffectLifecyclePolicy
- Controls when and how an owned Runtime shuts down.
- BetterEffectProvider
- Places an existing Runtime in the Flutter tree with explicit ownership.
- BetterEffectScope
- Exposes a long-lived better_effect Runtime and its EffectCommands to a Flutter subtree.
- Binding
- A declarative service registration used inside a Module.
- CancellationSignal
- A cooperative cancellation signal exposed to an active Effect.
- CleanupFailureDiagnostic
- Describes a cleanup failure reported after an Effect outcome was known.
- CleanupFailureEvent
- Runtime-observer projection of an existing cleanup diagnostic.
- CommandPolicy
- Immutable execution and timing policy for an Effect Command.
-
Effect<
A extends Object, E extends Object> -
A lazy computation that can succeed with
Aor fail withE. - EffectClock
- A replaceable source of wall-clock time and cooperative delays.
-
EffectCommand<
I, A extends Object, E extends Object> - An Effect command with one typed input.
-
EffectCommand0<
A extends Object, E extends Object> - An Effect command without input parameters.
-
EffectCommandBase<
A extends Object, E extends Object> - A Flutter-facing command that executes typed Effect values through a long-lived Runtime.
-
EffectCommandBuilder<
A extends Object, E extends Object> - A typed Command-state builder with optional transition filtering.
-
EffectCommandConsumer<
A extends Object, E extends Object> - Combines one-shot command side effects with state-driven UI rendering.
-
EffectCommandDefect<
A extends Object, E extends Object> - The Effect terminated because of an unexpected defect.
- EffectCommandDisposable
- The minimal lifecycle contract shared by all Effect command variants.
-
EffectCommandFailure<
A extends Object, E extends Object> - The Effect completed with an expected, typed failure.
-
EffectCommandIdle<
A extends Object, E extends Object> - The command has not started, or has been reset.
-
EffectCommandInterrupted<
A extends Object, E extends Object> - The command stopped owning an active execution result.
-
EffectCommandListener<
A extends Object, E extends Object> - Delivers command transitions as one-shot Flutter presentation effects.
- EffectCommandPolicyEvent
- Immutable diagnostic event for Command policy decisions.
-
EffectCommandRunning<
A extends Object, E extends Object> - The command is executing an Effect.
- EffectCommands
- Creates EffectCommand0 and EffectCommand instances bound to one long-lived Runtime.
-
EffectCommandSelector<
A extends Object, E extends Object, S> - Rebuilds only when a selected Command value changes.
-
EffectCommandSnapshot<
A extends Object, E extends Object> - Read-only state and coordination metadata for one Command.
-
EffectCommandState<
A extends Object, E extends Object> - The observable UI state of an EffectCommandBase.
-
EffectCommandSuccess<
A extends Object, E extends Object> - The Effect completed successfully.
- EffectCommandTransition
- One state transition produced by an Effect command.
-
EffectContext<
E extends Object> - The capabilities available inside Effect.result.
-
EffectExecution<
A extends Object, E extends Object> - A managed handle for one Effect execution.
-
EffectLocal<
T extends Object> - A runtime-local value inherited by nested Effects.
- EffectLocalBinding
- A heterogeneous, type-safe local binding.
- EffectRandom
- A replaceable source of uniform random values for Effect policies.
- EffectViewModel
- Optional MVVM base class with concise, automatically disposed command creation.
-
EffectViewModelBuilder<
T extends ChangeNotifier> - Creates, observes, and disposes a ViewModel at a Flutter composition boundary without imposing Provider, Riverpod, BLoC, or another state package.
- ExecutionEndEvent
- Emitted synchronously after physical work and Scope cleanup finish.
- ExecutionStartEvent
- Emitted synchronously immediately before an Effect runner starts.
-
Exit<
A extends Object, E extends Object> - The complete outcome of running an Effect.
-
ExitDefect<
A extends Object, E extends Object> - An Effect terminated because of an unexpected defect.
-
ExitFailure<
A extends Object, E extends Object> - An Effect completed with an expected, typed failure.
-
ExitInterrupted<
A extends Object, E extends Object> - Execution or runtime ownership ended without a success or typed failure.
-
ExitSuccess<
A extends Object, E extends Object> - An Effect completed successfully.
-
Failure<
S extends Object, F extends Object> - Error Result.
- InterruptionEvent
- Emitted once when a managed execution first receives cancellation.
- Module
- A composable collection of service bindings.
- ResolverBackend
- Backend contract used by Runtime to register and resolve services.
- ResolverBackendOverlayFactory
- Optional backend capability used by execution-scoped Modules and child Runtime environments.
- ResourceReleaseEvent
- Describes release of one Module or Effect resource.
-
ResultDart<
S extends Object, F extends Object> - Base Result class
-
RetryContext<
E extends Object> - Information available when a typed failure asks a RetryPolicy whether another attempt should run.
- RetryEvent
- Immutable projection of one retry decision.
-
RetryPolicy<
E extends Object> - Decides the delay before another execution of an Effect.
- Runtime
- Executes Effects against the environment built from a Module.
- RuntimeEventContext
- Immutable execution and metadata projection shared by Runtime events.
- RuntimeObserver
- SDK-neutral, synchronous Runtime instrumentation.
- RuntimeObserverError
- A callback failure that was isolated from execution semantics.
- Scope
- Owns finalizers, resources, and child Scopes.
- SeededEffectRandom
- Reproducible pseudo-random source for tests and deterministic simulations.
- ServiceAcquireEvent
- Describes acquisition of one Module or Effect resource.
-
ServiceKey<
T extends Object> - A typed name for distinguishing multiple implementations of the same type.
- ServiceResolveEvent
- Describes one service-resolution attempt.
- Services
- A read-only, callable view of the services available in a Runtime.
-
Success<
S extends Object, F extends Object> - Success Result.
- SystemEffectClock
-
Host-backed EffectClock using
DateTime.nowandFuture.delayed. - SystemEffectRandom
- Host-backed pseudo-random source.
- TriggerPolicy
- Immutable timing policy for typed-input Commands.
- Unit
-
Used instead of
voidas a return statement for a function when no value is to be returned.
Enums
- BetterEffectRuntimeOwnership
- Declares who owns a Runtime placed in the Flutter tree.
- CommandPolicyDecision
- A policy decision that does not need a new Command state or domain failure.
- CommandPolicyKind
- Execution coordination used by a CommandPolicy.
- CommandPolicyReason
- Machine-readable reason attached to EffectCommandPolicyEvent.
- EffectCommandConcurrency
- Compatibility shorthand for the three original Command coordination modes.
- InterruptionSource
- Which owner requested cooperative interruption.
- Lifetime
- Controls how a constructor-backed service is instantiated.
- QueueOverflow
- Behavior when a bounded Command queue has no remaining capacity.
- ResourceAcquisitionSource
- Which API acquired a scoped resource.
- RetryDecision
- Why a retry loop continued or stopped after one attempt.
- RuntimeObserverCallback
- Identifies the observer callback that raised an instrumentation error.
- RuntimeState
- Lifecycle state of a Runtime.
- ServiceResolutionSource
- How a service request was satisfied.
- TriggerPolicyKind
- Timing stage applied before execution coordination.
Mixins
- EffectCommandOwner
- Disposes every Effect command owned by a ChangeNotifier.
Extensions
-
AsyncResultDartEffectInterop
on AsyncResultDart<
A, E> - Convert an asynchronous Result into an Effect.
-
AsyncResultDartExtension
on AsyncResultDart<
S, F> -
AsyncResultDart<S, E>represents an asynchronous computation. - BetterEffectBuildContext on BuildContext
- Flutter accessors for the nearest BetterEffectScope.
- EffectCommandConcurrencyPolicy on EffectCommandConcurrency
- Translate the compatibility enum into its exact immutable policy.
-
EffectRetryOps
on Effect<
A, E> - Typed-failure retry for every Effect.
-
EffectTransformOps
on Effect<
A, E> - Transformations available on every Effect.
-
FlattenAsyncResultExtension
on AsyncResultDart<
ResultDart< S, F> , F> - Extension to flatten a nested AsyncResultDart into a single AsyncResultDart.
-
FlattenResultExtension
on ResultDart<
ResultDart< S, F> , F> - Extension to flatten a nested ResultDart into a single ResultDart.
-
FutureResultExtension
on Future<
S> -
Extension on
Future<S>to convert it into anAsyncResultDart<S, Exception>. -
FutureResultExtensionVoid
on Future<
void> -
Extension on
Future<void>to convert it into anAsyncResultDart<Unit, Exception>. -
ResultDartEffectInterop
on ResultDart<
A, E> - Convert a synchronous Result into a lazy Effect value.
- ResultObjectExtension on W
-
Adds methods for converting any object
into a
Resulttype (SuccessorFailure). - RuntimeChildOps on Runtime
- Child Runtime operations for feature-length environments.
- RuntimeExecutionModuleOps on Runtime
- Execution-scoped Module operations for a long-lived Runtime.
Constants
Functions
-
runBetterEffectApp(
{required Module module, required Widget app, ResolverBackend? backend, EffectCommandObserver? observer, EffectCommandPolicyObserver? policyObserver, BetterEffectLifecyclePolicy lifecyclePolicy = const BetterEffectLifecyclePolicy.application(), bool? closeRuntimeOnDetach, BetterEffectStartupErrorBuilder? startupErrorBuilder, void onRuntimeCloseError(Object error, StackTrace stackTrace)?}) → Future< void> - Starts an application-owned better_effect Runtime and mounts Flutter.
Typedefs
-
AsyncResult<
S extends Object> = AsyncResultDart< S, Exception> -
A typedef for an asynchronous
Result, simplifying the usage ofAsyncResultDartwithExceptionas the default failure type. -
AsyncResultDart<
S extends Object, F extends Object> = Future< ResultDart< S, F> > -
AsyncResultDart<S, E>represents an asynchronous computation. - BetterEffectBackendFactory = ResolverBackend Function()
- Creates a fresh resolver backend whenever BetterEffectBootstrap starts or retries.
- BetterEffectBootstrapBuilder = Widget Function(BuildContext context)
- Builds the application subtree after the Runtime starts.
- BetterEffectBootstrapErrorBuilder = Widget Function(BuildContext context, Object error, StackTrace stackTrace, VoidCallback retry)
-
Builds a startup error UI. Calling
retrystarts a fresh Runtime. - BetterEffectFeatureBuilder = Widget Function(BuildContext context)
- Builds a feature subtree after its child Runtime has started.
- BetterEffectFeatureErrorBuilder = Widget Function(BuildContext context, Object error, StackTrace stackTrace, VoidCallback retry)
- Builds the startup-error state for a feature child Runtime.
- BetterEffectStartupErrorBuilder = Widget Function(Object error, StackTrace stackTrace)
- Builds a fallback root when the application Runtime cannot start.
-
CleanupFailureObserver
= FutureOr<
void> Function(CleanupFailureDiagnostic diagnostic) - Receives cleanup failures without changing the main Effect outcome.
-
EffectBody<
A extends Object, E extends Object> = FutureOr< A> Function(EffectContext<E> use) - A lazy Effect body with access to contextual services and typed failures.
-
EffectCommandBuildWhen<
A extends Object, E extends Object> = bool Function(EffectCommandState< A, E> previous, EffectCommandState<A, E> current) - Decides whether one state transition should rebuild the subtree.
-
EffectCommandChanged<
A extends Object, E extends Object> = void Function(BuildContext context, EffectCommandState< A, E> state) -
EffectCommandDefectListener<
A extends Object> = void Function(BuildContext context, Object defect, StackTrace stackTrace, A? previous) -
EffectCommandFailureListener<
A extends Object, E extends Object> = void Function(BuildContext context, E error, A? previous) -
EffectCommandIdleListener<
A extends Object> = void Function(BuildContext context, A? previous) -
EffectCommandInterruptedListener<
A extends Object> = void Function(BuildContext context, A? previous) -
EffectCommandListenWhen<
A extends Object, E extends Object> = bool Function(EffectCommandState< A, E> previous, EffectCommandState<A, E> current) - Decides whether a transition should be delivered to a listener.
- EffectCommandObserver = void Function(EffectCommandTransition transition)
- Observes transitions from every command created by one EffectCommands instance.
- EffectCommandPolicyObserver = void Function(EffectCommandPolicyEvent event)
- Observes policy decisions from one or more Commands.
-
EffectCommandRunningListener<
A extends Object> = void Function(BuildContext context, A? previous) -
EffectCommandSelectedWidgetBuilder<
S> = Widget Function(BuildContext context, S selected, Widget? child) - Builds a subtree from a selected Command value.
-
EffectCommandSelectionEquals<
S> = bool Function(S previous, S current) - Compares previous and current selected values.
-
EffectCommandSnapshotSelector<
A extends Object, E extends Object, S> = S Function(EffectCommandSnapshot< A, E> snapshot) - Selects one strongly typed value from a read-only Command snapshot.
-
EffectCommandStateObserver<
A extends Object, E extends Object> = void Function(EffectCommandState< A, E> state) - Observes every visible state published by one command.
-
EffectCommandStateSelector<
A extends Object, E extends Object, S> = S Function(EffectCommandState< A, E> state) - Selects one strongly typed value from a Command state.
-
EffectCommandSuccessListener<
A extends Object> = void Function(BuildContext context, A value) -
EffectCommandWidgetBuilder<
A extends Object, E extends Object> = Widget Function(BuildContext context, EffectCommandState< A, E> state, Widget? child) - Builds a Widget from the current typed command state.
- ReleaseFailure = ({Object error, StackTrace stackTrace})
- A finalizer failure captured while closing a Scope.
-
ResourceAcquire<
T extends Object> = FutureOr< T> Function(Services services) - Creates a resource using services already available in the module.
-
ResourceRelease<
R extends Object> = FutureOr< void> Function(R resource, Exit<Object, Object> exit) - Releases a resource with the outcome that closed its owning Scope.
-
Result<
S extends Object> = ResultDart< S, Exception> -
A typedef for a
Resultthat simplifies the usage ofResultDartwithExceptionas the default failure type. - RuntimeObserverErrorHandler = void Function(RuntimeObserverError error)
- Reports failures raised by RuntimeObserver callbacks.
-
ScopeFinalizer
= FutureOr<
void> Function(Exit<Object, Object> exit) - A cleanup callback registered with a Scope.
Exceptions / Errors
- CompositeDefect
- Preserves a primary defect together with another defect raised during cleanup.
- DuplicateServiceBindingException
- Thrown when a Module contains more than one binding for the same service.
- ResolverBackendOverlayUnsupportedException
- Reported when a custom backend cannot create an isolated child overlay.
- ResourceAcquisitionException
- Identifies the Module resource whose acquisition failed.
- RuntimeClosedException
- Thrown when an operation is attempted after a Runtime stops accepting work.
- ScopeClosedException
- Thrown when new work is added to a Scope after closing starts.
- ScopeReleaseException
- Aggregates one or more defects raised while releasing scoped resources.