PersistSignal<T> class
A signal that persists its value to external storage.
PersistSignal automatically saves its value to external storage whenever it changes and loads the initial value from storage when created. It supports both synchronous and asynchronous read/write operations.
Example:
final theme = PersistSignal(
initialValue: () => 'light',
read: () => SharedPreferences.getInstance()
.then((prefs) => prefs.getString('theme') ?? 'light'),
write: (value) => SharedPreferences.getInstance()
.then((prefs) => prefs.setString('theme', value)),
);
theme.value = 'dark'; // Automatically saved to storage
- Inheritance
-
- Object
- ReactiveNode
- JReadonlyValue<
T> - Signal<
T> - PersistSignal
- Available extensions
Constructors
-
PersistSignal({T initialValue()?, required FutureOr<
T> read(), required FutureOr<void> write(T value), bool lazy = false, Duration writeDelay = Duration.zero, JoltDebugFn? onDebug}) - Creates a persistent signal with the given configuration.
-
PersistSignal.lazy({T initialValue()?, required FutureOr<
T> read(), required FutureOr<void> write(T value)}) -
Creates a lazy persistent signal that loads its value on first access.
factory
Properties
- deps ↔ Link?
-
First dependency link in the chain.
getter/setter pairinherited
- depsTail ↔ Link?
-
Last dependency link in the chain.
getter/setter pairinherited
- flags ↔ int
-
Reactive flags for this node.
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasInitialized ↔ bool
-
Whether the signal has been initialized from storage.
getter/setter pair
- isDisposed ↔ bool
-
Whether this reactive value has been disposed.
getter/setter pairinherited
-
listenable
→ JoltValueListenable<
T> -
Available on JReadonlyValue<
Converts this Jolt value to a Flutter ValueListenable.T> , provided by the JoltValueListenableExtension extensionno setter -
notifier
→ JoltValueNotifier<
T> -
Available on JReadonlyValue<
Converts this Jolt value to a Flutter ValueNotifier.T> , provided by the JoltValueNotifierExtension extensionno setter - peek → T
-
Returns the current value without establishing a reactive dependency.
no setterinherited
- pendingValue ↔ Object?
-
Internal storage for the node's value.
getter/setter pairinherited
-
read
→ FutureOr<
T> Function() -
Function to read the value from storage.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ Stream<
T> -
Available on JReadonlyValue<
Converts this reactive value to a broadcast stream.T> , provided by the JoltStreamValueExtension extensionno setter - subs ↔ Link?
-
First subscriber link in the chain.
getter/setter pairinherited
- subsTail ↔ Link?
-
Last subscriber link in the chain.
getter/setter pairinherited
- value ↔ T
-
Returns the current value and establishes a reactive dependency.
getter/setter pairinherited
-
write
→ FutureOr<
void> Function(T value) -
Function to write the value to storage.
final
- writeDelay → Duration
-
Delay before writing to storage (for debouncing).
final
Methods
-
dispose(
) → void -
Disposes this reactive value and cleans up resources.
inherited
-
ensure(
FutureOr< void> fn()?) → Future<void> - Ensures the signal is initialized and runs the given function.
-
get(
) → T -
Returns the current value and establishes a reactive dependency.
override
-
getEnsured(
) → Future< T> - Gets the value and ensures it's loaded from storage.
-
listen(
void onData(T event)?, {Function? onError, void onDone()?, bool? cancelOnError, bool immediately = false}) → StreamSubscription< T> -
Available on JReadonlyValue<
Creates a stream subscription that listens to changes in this reactive value.T> , provided by the JoltStreamValueExtension extension -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notify(
) → void -
Manually notifies all subscribers that this signal has changed.
inherited
-
onDispose(
) → void -
Disposes the signal and cleans up resources.
inherited
-
readonly(
) → ReadonlySignal< T> -
Available on Signal<
Returns a read-only view of this signal.T> , provided by the JoltSignalExtension extension -
set(
T value) → void -
Sets a new value for the signal.
override
-
testNoSubscribers(
) → bool -
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited