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
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<T>, provided by the JoltValueListenableExtension extension

Converts this Jolt value to a Flutter ValueListenable.
no setter
notifier JoltValueNotifier<T>

Available on JReadonlyValue<T>, provided by the JoltValueNotifierExtension extension

Converts this Jolt value to a Flutter ValueNotifier.
no 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<T>, provided by the JoltStreamValueExtension extension

Converts this reactive value to a broadcast stream.
no 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<T>, provided by the JoltStreamValueExtension extension

Creates a stream subscription that listens to changes in this reactive value.
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<T>, provided by the JoltSignalExtension extension

Returns a read-only view of this signal.
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