jolt_surge library
A lightweight state management library for Flutter based on Jolt Signals.
Jolt Surge is inspired by the Cubit pattern from the BLoC library. It provides a signal-based state management solution that combines Jolt's reactive signal system with Flutter's state management capabilities.
Documentation
Main Components:
- Surge: The state container class that manages state reactively
- SurgeProvider: Provides Surge instances to the widget tree
- SurgeConsumer: Unified widget for both building UI and handling side effects
- SurgeBuilder: Convenient widget for building UI based on state
- SurgeListener: Convenient widget for handling side effects only
- SurgeSelector: Fine-grained rebuild control using selector functions
Example:
import 'package:jolt_surge/jolt_surge.dart';
// Create a Surge
class CounterSurge extends Surge<int> {
CounterSurge() : super(0);
void increment() => emit(state + 1);
void decrement() => emit(state - 1);
}
// Use in Flutter
SurgeProvider<CounterSurge>(
create: (_) => CounterSurge(),
child: SurgeBuilder<CounterSurge, int>(
builder: (context, state, surge) => Text('Count: $state'),
),
);
This design maintains the predictability and simplicity of the Cubit pattern while leveraging the reactive capabilities of Jolt Signals, enabling you to build efficient and maintainable state management solutions in Flutter.
Classes
- MultiSurgeProvider
- A convenience widget that provides multiple Surge instances to the widget tree.
-
Surge<
State> - Base class for state management in the Surge pattern.
-
SurgeBuilder<
T extends Surge< S> , S> - A widget that builds UI based on Surge state changes.
-
SurgeConsumer<
T extends Surge< S> , S> - A unified widget that provides both builder and listener functionality.
-
SurgeListener<
T extends Surge< S> , S> - A widget that listens to Surge state changes for side effects.
-
SurgeProvider<
T extends Surge> - A widget that provides a Surge instance to the widget tree.
-
SurgeSelector<
T extends Surge< S> , S, C> - A widget that provides fine-grained rebuild control using a selector function.
Typedefs
-
SurgeStateCreator<
T> = WritableNode< T> Function(T state) - Function type for creating a writable reactive value from initial state.