main library
A reactive state management library for Flutter with automatic dependency tracking.
This library provides a comprehensive set of tools for managing state in Flutter applications, inspired by MobX and Vue's reactivity system.
Features
- Reactive State (SwiftValue): Automatic dependency tracking with SwiftValue and swift
- Two Patterns: Direct state management OR Controller pattern with enforced separation
- Swift-like Extensions: 80+ convenient methods (toggle, add, sub, mul, div, etc.)
- Mark Widget: Auto-rebuild widget that tracks dependencies automatically
- Computed Values: Derived state that automatically updates when dependencies change
- Async State: SwiftFuture for managing loading/error/success states
- Form Validation: SwiftField with built-in validators
- Persistence: SwiftPersisted for automatic save/load of reactive values
- Middleware/Interceptors: Action interception and logging system
- Batch Transactions: Prevent unnecessary rebuilds with Transaction
- Debug Logging: Configurable logging with history via Logger
- Animation Tween: Reactive animation values with SwiftTween
- Lifecycle Controller: Widget lifecycle state management
- Global Store/DI: Dependency injection and global state management
Quick Start
import 'package:swift_flutter/swift_flutter.dart';
// Pattern 1: Direct state management (for view-local state)
final counter = swift(0);
Swift(
builder: (context) => Text('Count: ${counter.value}'),
)
counter.value = 10; // Direct modification
// Pattern 2: Controller pattern (for business logic)
class CounterController extends SwiftController {
final counter = swift(0);
void increment() => counter.value++;
}
See the README for more examples.
Classes
-
AsyncValue<
T> - Wrapper for async values with loading/error states
- AutoInjector
- Public API for automatic HTTP interception
-
Computed<
T> - Computed value that automatically updates when dependencies change
- ComputedTracker
- Tracker for computed dependencies
- ComputedTrackerRegistry
- Registry for computed trackers (stack-based)
- DebugLogger
- Enhanced logger with context
- DebugMode
- Debug mode configuration
- ErrorBoundary
- Error boundary for safe state updates with error recovery
- ErrorBoundaryWidget
- Error boundary widget that catches errors in widget tree
- ExampleAction
- Example action implementation
- HttpInterceptorHelper
- Helper to intercept HTTP requests made with http package
- InterceptedLogEntry
- Log entry model for intercepted logs
- InterceptingHttpOverrides
- InterceptingHttpOverrides: returns an intercepting HttpClient
-
LazyRx<
T> - Lazy reactive state that only loads when first accessed
- LifecycleController
- Lifecycle controller for managing widget/component lifecycle
- LogEntry
- Log entry
- Logger
- Logger for debugging reactive state changes
- LoggingMiddleware
- Logging middleware
- LogInterceptor
- Log interceptor to capture print statements and logs
- MarkRegistry
- Registry for tracking active Mark widgets (stack-based for nested support)
- MemoryStorage
- SharedPreferences-like storage (requires shared_preferences package in real implementation)
- Middleware
- Middleware interface for intercepting actions
-
MigrationConfig<
T> - Migration configuration
- MigrationHelper
- Migration helper utilities
- MockReactiveState
- Mock reactive state for testing
- Helper for integrating with Navigator
- NetworkInterceptor
- Network interceptor to capture HTTP requests and responses
- NetworkRequest
- Network request/response data model
- NetworkResponse
- Network response data model
-
NormalizedState<
T> - Normalized state structure for managing collections
- OpinionatedPatterns
- Common opinionated patterns
-
OpinionatedStore<
T> - Opinionated state management helper Provides common patterns out of the box
-
OpinionatedStoreBuilder<
T> - Builder for creating opinionated stores
-
PaginationController<
T> - Reactive pagination controller
-
PaginationState<
T> - Pagination state
- PerformanceMonitor
- Performance monitoring for reactive state updates and widget rebuilds
-
ReactiveChain<
T> - Type-safe reactive chain builder
-
ReadOnlyRx<
T> - Read-only wrapper for Rx that prevents direct state mutation from views.
-
ReduxStore<
T> - Store with Redux-like reducer pattern
- RetryConfig
- Retry configuration for async operations
- RoutingState
- Routing state management for navigation Provides reactive navigation state that can be used with any routing solution
-
RxBuilder<
T> - Builder widget that rebuilds when Rx values change
-
RxNormalizedState<
T> - Reactive normalized state
- RxRouting
- Reactive routing state manager Works with any routing solution (go_router, Navigator, etc.)
- StorageBackend
- Interface for storage backends
- Store
- Global store for dependency injection and state management
-
StructuredState<
TState, TEvent> - Structured state management pattern (Bloc-like but simpler) Provides opinionated structure for state management
-
StructuredStore<
TState, TEvent> - Structured state manager (Bloc-like pattern)
- Swift
- Widget that automatically rebuilds when its reactive dependencies change.
- SwiftController
- Base class for controllers that manage state.
- SwiftDebugFloatingButton
- Floating action button to access debug page
- SwiftDebugPage
- Debug page to view network requests, responses, and logs
- SwiftDevTools
- DevTools integration for Swift Flutter
-
SwiftField<
T> - Form field with validation
- SwiftFlutter
- Main initialization class for Swift Flutter
-
SwiftFuture<
T> - Reactive Future wrapper that tracks loading/error states with retry and error recovery
-
SwiftFuturePagination<
T> - Pagination helper for SwiftFuture
- SwiftHttpHelper
- Helper class to intercept HTTP requests made with the http package
-
SwiftPersisted<
T> - Reactive value with persistence
- SwiftScope
- Scoped state management for isolating state per feature/module
- SwiftState
- Internal state interface for Mark widget
- SwiftTestHelpers
- Testing utilities for swift_flutter
-
SwiftTween<
T> - Reactive tween that animates between values using AnimationController
-
SwiftValue<
T> - Reactive state container that automatically tracks dependencies
- SwiftViewInterceptor
- View interceptor to show debug page
- SwiftWebSocket
- Helper class to create intercepted WebSocket connections
- Transaction
- Transaction context for batching multiple updates
- TweenHelper
- Helper for creating common tweens
-
TypedComputed<
T> - Type-safe computed value
-
TypedRx<
T> - Type-safe reactive value with compile-time checks Provides better type safety than plain Rx<T>
- TypeGuard
- Type guard for runtime type checking
- Validators
- Common validators
- WebSocketConnection
- WebSocket connection model
- WebSocketEvent
- WebSocket event model
- WebSocketInterceptor
- WebSocket interceptor to capture WebSocket connections and events
Enums
- AsyncState
- Represents the state of an async operation
- ErrorRecoveryStrategy
- Error recovery strategy
- LifecycleState
- Lifecycle states
- LogLevel
- Log levels
- LogType
- Log types
- WebSocketEventType
- WebSocket event types
Mixins
-
LifecycleMixin<
T extends StatefulWidget> - Widget mixin for lifecycle management
Extensions
- HttpResponseInterceptor on Future
- Extension to make it easier to intercept http.Response
-
RxTypeSafety
on Rx<
T> - Extension for better type safety on Rx
- TransactionNotifier on ChangeNotifier
- Extension to make ChangeNotifier transaction-aware.
Functions
-
applyMiddleware<
T> (Reducer< T> reducer, List<ReduxMiddleware< middlewares) → Reducer<T> >T> - Apply middleware to a reducer
-
combineReducers<
T> (Map< String, Reducer< reducers) → Reducer<T> >T> - Combine multiple reducers into one
-
denormalize<
T> (Map< String, T> normalized) → List<T> - Denormalize a map of entities into a list
-
normalize<
T> (List< T> entities, IdExtractor<T> extractId) → Map<String, T> - Normalize a list of entities into a map
-
swift<
T> (T value, {String? name}) → SwiftValue< T> - Creates a SwiftValue with optional type inference.
-
swiftPrint(
Object? object, {StackTrace? stackTrace}) → void - Custom print function that captures logs
Typedefs
-
EventHandler<
TState, TEvent> = TState Function(TState state, TEvent event) - Event handler function type
-
IdExtractor<
T> = String Function(T entity) - Helper to extract ID from entity
-
MigrationFunction<
T> = T Function(Map< String, dynamic> oldData, int fromVersion, int toVersion) - Migration function type
-
Reducer<
T> = T Function(T state, Action action) - Reducer function type
-
ReduxMiddleware<
T> = void Function(ReduxStore< T> store, Action action, void next(Action)) - Middleware for Redux store
-
Rx<
T> = SwiftValue< T> - Backward compatibility alias - Rx is now SwiftValue
-
Validator<
T> = String? Function(T value) - Validation function type
Exceptions / Errors
- TimeoutException
- Exception thrown when a condition timeout occurs