JoltState class abstract
Base class for objects that need lifecycle management in JoltProvider.
Classes extending JoltState receive mount and unmount notifications when used with JoltProvider, allowing for proper resource management and cleanup. Both callbacks have default empty implementations, so you only need to override the ones you need.
Lifecycle
- onMount is called after the resource is created and the widget is mounted
- onUnmount is called when the widget is unmounted or when a new resource is created to replace this one
Example
class MyStore extends JoltState {
final counter = Signal(0);
Timer? _timer;
@override
void onMount(BuildContext context) {
super.onMount(context);
_timer = Timer.periodic(Duration(seconds: 1), (_) {
counter.value++;
});
}
@override
void onUnmount(BuildContext context) {
super.onUnmount(context);
_timer?.cancel();
_timer = null;
}
}
Resources that don't need lifecycle management don't need to extend JoltState:
class SimpleStore {
final counter = Signal(0);
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onMount(
BuildContext context) → void - Called when the resource is mounted to the widget tree.
-
onUnmount(
BuildContext context) → void - Called when the resource is unmounted from the widget tree.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited