Signal that persists its value to external storage.
Automatically saves value changes to storage. Supports sync/async reads, lazy loading, and write throttling. Uses a 2-element write queue.
Initialization:
- Sync signals: initialized immediately (or on first access if lazy)
- Async signals: must call ensure or getEnsured before writing
Example (sync):
final theme = PersistSignal.sync(
read: () => prefs.getString('theme') ?? 'light',
write: (value) => prefs.setString('theme', value),
);
theme.value = 'dark'; // Auto-saved
Example (async):
final theme = PersistSignal.async(
read: () async => await prefs.getString('theme') ?? 'light',
write: (value) => prefs.setString('theme', value),
initialValue: () => 'light',
);
await theme.ensure(); // Wait for init
theme.value = 'dark'; // Auto-saved
- Implemented types
-
- Signal<
T>
- Signal<
- Implementers
- Available extensions
Constructors
-
PersistSignal.async({required Future<
T> read(), required FutureOr<void> write(T value), T initialValue()?, bool lazy, Duration? throttle, JoltDebugFn? onDebug}) -
Creates an asynchronous persistent signal.
factory
-
PersistSignal.lazyAsync({required Future<
T> read(), required FutureOr<void> write(T value), T initialValue()?, Duration? throttle, JoltDebugFn? onDebug}) -
Creates a lazy asynchronous persistent signal.
factory
-
PersistSignal.lazySync({required T read(), required FutureOr<
void> write(T value), Duration? throttle, JoltDebugFn? onDebug}) -
Creates a lazy synchronous persistent signal.
factory
-
PersistSignal.sync({required T read(), required FutureOr<
void> write(T value), bool lazy, Duration? throttle, JoltDebugFn? onDebug}) -
Creates a synchronous persistent signal.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether this node has been disposed.
no setterinherited
- isInitialized → bool
-
Whether initialized from storage.
no setter
- peek → T
-
Gets the current value without establishing a reactive dependency.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ Stream<
T> -
Available on Readable<
Converts this reactive value to a broadcast stream.T> , provided by the JoltUtilsStreamExtension extensionno setter - value ↔ T
-
Gets the current value and establishes a reactive dependency.
getter/setter pairinherited
Methods
-
call(
) → T -
Available on Readable<
Gets the current value (callable syntax).T> , provided by the JoltUtilsReadableExtension extension -
derived<
U> (U computed(T value)) → Computed< U> -
Available on Readable<
Creates a computed value derived from this readable.T> , provided by the JoltUtilsReadableExtension extension -
dispose(
) → void -
Disposes this node and cleans up resources.
inherited
-
ensure(
[FutureOr< void> fn(T value)?]) → Future<void> - Ensures initialization, optionally running a function.
-
ensureWrite(
) → Future< void> - Waits for all pending writes to complete.
-
get(
) → T -
Available on Readable<
Gets the current value.T> , provided by the JoltUtilsReadableExtension extension -
getEnsured(
) → Future< T> - Gets value, ensuring initialization is complete.
-
listen(
void onData(T event)?, {Function? onError, void onDone()?, bool? cancelOnError, bool immediately = false}) → StreamSubscription< T> -
Available on Readable<
Listens to changes in this reactive value.T> , provided by the JoltUtilsStreamExtension extension -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notify(
) → void -
Triggers a change notification without modifying the value.
inherited
-
readonly(
) → ReadonlySignal< T> -
Available on Signal<
Returns a read-only view of this signal.T> , provided by the JoltSignalExtension extension -
set(
T value) → T -
Available on Writable<
Sets the value.T> , provided by the JoltUtilsWritableExtension extension -
toString(
) → String -
A string representation of this object.
inherited
-
until(
bool predicate(T value)) → Future< T> -
Available on ReadableNode<
Waits until the value satisfies a condition.T> , provided by the JoltUtilsUntilExtension extension -
untilWhen<
U> (U predicate) → Future< T> -
Available on ReadableNode<
Waits until the reactive value equals a specific value.T> , provided by the JoltUtilsUntilExtension extension -
update(
T updater(T value)) → T -
Available on Writable<
Updates the value using an updater function based on the current value.T> , provided by the JoltUtilsWritableExtension extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited