PersistedNode<T> class

A specialized ZenithNode that automatically restores state from a ZenithStorage backend on creation and saves updates on mutation.

final themeNode = PersistedNode.string(
  key: 'app.theme',
  defaultValue: 'system',
  storage: localStorage,
);

print(themeNode.value); // Restored from storage, or 'system'
themeNode.set('dark');  // Mutates node & asynchronously writes to storage
Inheritance
Available extensions

Constructors

PersistedNode({required String key, required T defaultValue, required ZenithStorage storage, required String toStorage(T value), required T fromStorage(String raw)})
Creates a PersistedNode with custom serialization callbacks.

Properties

debugSubscriberCount → int
The current number of subscribers (including potentially dead weak references that have not yet been pruned).
no setterinherited
fromStorage → T Function(String raw)
Deserializer callback parsing String back into T.
final
hashCode → int
The hash code for this object.
no setterinherited
isDisposed → bool
Whether this node has been disposed.
no setterinherited
key → String
The key used for storage lookup.
final
persistenceError → Object?
Latest write/serialization failure, cleared after a successful write.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
storage → ZenithStorage
The storage backend powering this node.
final
toStorage → String Function(T value)
Serializer callback converting T to a String.
final
value ↔ T
The current value held by this node.
getter/setter pairinherited

Methods

dispose({bool purgeZeroize = false}) → void
Permanently disposes this node, clearing all subscribers.
inherited
flush() → Future<void>
Awaits this node's latest accepted write and propagates its failure. Call before ending a scope when durability is required.
guard(ZenithRef ref, Future<T> future()) → Future<void>

Available on ZenithNode<AsyncValue<T>>, provided by the SafeAsyncNodeX extension

Executes future and writes its result to this node, guarding every mutation with ref's lifecycle. Equivalent to ref.runAsync(this, future).
invalidate() → void
Forces a notification pass without changing the value.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifySubscribers() → void
Notifies all live subscribers that this node has changed.
inherited
set(T newValue) → void
Sets the value of this node and notifies all active subscribers.
override
subscribe(ZenithSubscriber subscriber) → ZenithSubscription
Adds subscriber to this node's listener set.
inherited
toString() → String
A string representation of this object.
inherited
trySet(T newValue) → bool
Attempts to update the value of this node.
inherited
unsubscribe(ZenithSubscriber subscriber) → void
Removes subscriber from this node's listener set.
inherited
watch(ZenithRef ref, Stream<T> stream) → StreamSubscription<T>

Available on ZenithNode<AsyncValue<T>>, provided by the StreamNodeX extension

Subscribes to stream and writes each event to this node, guarding every mutation with ref's lifecycle.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

boolean({required String key, required bool defaultValue, required ZenithStorage storage}) → PersistedNode<bool>
Helper for boolean persisted nodes.
integer({required String key, required int defaultValue, required ZenithStorage storage}) → PersistedNode<int>
Helper for integer persisted nodes.
string({required String key, required String defaultValue, required ZenithStorage storage}) → PersistedNode<String>
Helper for string persisted nodes.