flowdux_flutter library
Flutter bindings for FlowDux state management library.
This library provides Flutter widgets for integrating FlowDux stores into Flutter applications.
Getting Started
- Wrap your app with StoreProvider:
void main() {
final store = createStore<AppState, AppAction>(
initialState: AppState(),
reducer: appReducer,
);
runApp(
StoreProvider<AppState, AppAction>(
store: store,
child: MyApp(),
),
);
}
- Use StoreBuilder to rebuild widgets when state changes:
StoreBuilder<AppState, AppAction>(
builder: (context, state) {
return Text('Count: ${state.count}');
},
)
- Use StoreConsumer to access both store and state:
StoreConsumer<AppState, AppAction>(
builder: (context, store, state) {
return ElevatedButton(
onPressed: () => store.dispatch(IncrementAction()),
child: Text('Count: ${state.count}'),
);
},
)
- Use StoreSelector for optimized rebuilds:
StoreSelector<AppState, AppAction, int>(
selector: (state) => state.count,
builder: (context, count) {
return Text('Count: $count');
},
)
Classes
- Action
- Base interface for all actions.
- AsyncLock
- Completer-based async lock for preventing async interleaving.
- ChainedStrategy
- A strategy composed of two chained strategies.
- ConcurrentStrategy
- Allows concurrent executions without any coordination. All actions execute independently without cancelling previous ones.
- DebounceStrategy
- Delays execution until no new actions arrive for the specified duration.
-
DebugStoreLogger<
S, A extends Action> - Debug logger that prints all events to the console.
-
DefaultErrorProcessor<
A extends Action> - Default error processor that swallows all errors.
-
ErrorProcessor<
A extends Action> - Error processor interface for handling errors in the middleware chain.
- ExecutionStrategy
- Defines how action processors should handle concurrent executions.
- FlowHolderAction
- Action that emits multiple actions via a Stream.
-
Middleware<
S, A extends Action> - Abstract base class for middleware.
-
NoOpStoreLogger<
S, A extends Action> - No-op logger that does nothing.
-
Processor<
S, A extends Action> - Defines an action processor with optional execution strategy.
-
ReducerBase<
S, A extends Action> - Base class for creating reducers with type-safe action handlers.
- RetryStrategy
- Retries failed processor executions.
- RetryWithBackoffStrategy
- Retries failed processor executions with exponential backoff.
- SequentialStrategy
- Queues actions and processes them one at a time, preserving order.
-
Store<
S, A extends Action> - Central state container for FlowDux.
-
StoreBuilder<
S, A extends Action> - A widget that rebuilds when the store's state changes.
-
StoreConsumer<
S, A extends Action> - A widget that provides both store access and state-based rebuilding.
-
StoreListener<
S, A extends Action> - A widget that listens to state changes without rebuilding.
-
StoreLogger<
S, A extends Action> - Logger interface for Store debugging and monitoring.
-
StoreProvider<
S, A extends Action> - Provides a Store to all descendant widgets.
-
StoreScope<
S, A extends Action> - Provides a Store with lifecycle ownership.
-
StoreSelector<
S, A extends Action, T> - A typed version of StoreBuilder that uses a selector to extract a specific value from the state.
-
StrategyBuilder<
S, A extends Action> - Builder for registering handlers with a shared execution strategy.
- TakeLatestStrategy
- Cancels any previous execution when a new action arrives. Only the latest action's result will be emitted.
- TakeLeadingStrategy
- Ignores new actions while one is still processing. Only the first action in a series will execute.
- ThrottleStrategy
- Limits execution rate by ignoring actions within a time window.
Enums
- FlowActionDelivery
- Determines how inner actions emitted by a FlowHolderAction are delivered.
- StrategyCategory
- Categories of execution strategies for validation during chaining.
Extensions
- ExecutionStrategyChaining on ExecutionStrategy
-
Extension to enable strategy chaining with the
thenmethod. - StoreProviderExtension on BuildContext
- Extension on BuildContext for convenient store access.
Functions
-
concurrent(
) → ExecutionStrategy - Creates a ConcurrentStrategy that allows concurrent executions.
-
createStore<
S, A extends Action> ({required S initialState, required Reducer< S, A> reducer, List<Middleware< middlewares = const [], ErrorProcessor<S, A> >A> ? errorProcessor, StoreLogger<S, A> ? logger}) → Store<S, A> - Creates a new Store with the given configuration.
-
debounce(
Duration duration) → ExecutionStrategy - Creates a DebounceStrategy that delays execution until no new actions arrive for the specified duration.
-
debounceMs(
int milliseconds) → ExecutionStrategy - Creates a DebounceStrategy with duration specified in milliseconds.
-
retry(
int maxAttempts, {bool retryIf(Object error)?}) → ExecutionStrategy - Creates a RetryStrategy that retries failed executions.
-
retryWithBackoff(
int maxAttempts, Duration initialDelay, {Duration? maxDelay, double factor = 2.0, double jitter = 0.0, bool retryIf(Object error)?}) → ExecutionStrategy - Creates a RetryWithBackoffStrategy that retries failed executions with exponential backoff.
-
sequential(
) → ExecutionStrategy - Creates a SequentialStrategy that queues actions and processes them one at a time.
-
takeLatest(
) → ExecutionStrategy - Creates a TakeLatestStrategy that cancels previous executions when a new action arrives.
-
takeLeading(
) → ExecutionStrategy - Creates a TakeLeadingStrategy that ignores new actions while one is processing.
-
throttle(
Duration duration) → ExecutionStrategy - Creates a ThrottleStrategy that limits execution rate.
-
throttleMs(
int milliseconds) → ExecutionStrategy - Creates a ThrottleStrategy with duration specified in milliseconds.
Exceptions / Errors
- CancellationException
- Exception thrown when an action's execution is cancelled.
- DuplicateCategoryException
- Exception thrown when attempting to chain strategies of the same category.
- DuplicateHandlerException
- Exception thrown when attempting to register a duplicate handler for the same action type.
- DuplicateProcessorException
- Exception thrown when attempting to register a duplicate action processor.