Pod<T> class

A versatile alternative to ValueNotifier.

It is designed to hold a single value and notifies listeners not only when the value itself changes but also when mutable states within the value change.

Limitations

Listeners will not be notified when mutable state within the value itself change:

final pod = Pod<List<int>>([0, 1, 2]);
pod.value.add(3); // This will NOT notify listeners

Solutions

  1. Notifying listeners with refresh:
pod.value.add(3);
pod.refresh(); // This will notify listeners
  1. Notifying listeners with set:
pod.set([3, 4, 5]); // This will notify listeners
  1. Notifying listeners with update:
pod.update((e) => e..add(3)); // This will notify listeners
  1. Notifying listeners with call or updateValue:
// These will notify listeners
pod().add(3);
pod.updateValue.add(3);

Parameters:

  • value: The initial value for the Pod.
  • temp: An optional flag to mark the Pod as temporary.
Inheritance
Implemented types
Mixed-in types
Implementers
Available extensions

Constructors

Pod(T value, {bool temp = false, bool disposable = true})
Creates a Pod<T>.
Pod.temp(T value)
Creates a temporary Pod<T>.

Properties

$children List<ChangeNotifier>
finalinherited
disposable bool
Whether this Pod is disposable. If false, the Pod will not be disposed when dispose is called. Instead, it will continue to exist until the application is closed.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isDisposed bool
Whether the Pod has been disposed.
no setter
markedAsTemp bool
Whether this Pod is marked as temporary. Pods marked as temporary are disposed by consumers like PodBuilder when they are no longer needed.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
updateValue → T
Gets this Pod's value and notifies any listeners.
no setter
value ↔ T
Gets this Pod's value without notifying any listeners.
getter/setter pairoverride

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
addSingleExecutionListener(VoidCallback listener) → void
Adds a listener to this Pod that is called only once.
override
bindChild<T extends ChangeNotifier>(T child) → T
Binds the ChangeNotifier child to this (the parent) so that the child will be disposed when this is disposed.
inherited
bindParent(BindWithMixin parent) → T

Available on T, provided by the BindParentOnChangeNotifierExtension extension

Binds this ChangeNotifier to parent so that it will be disposed when parent is disposed.
call() → T
Gets this Pod's value and notifies any listeners.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
disposeIfMarkedAsTemp() → void
Disposes this Pod and removes all listeners if it is marked as temporary.
override
map<B>(B reducer(T value), List<T> updateParents(B)?) ChildPod<T, B>
Maps this Pod to a new Pod using the specified reducer. Optionally, provide updateParents to define how parent Pods should be updated when this Pod changes.
mapToTemp<B>(B reducer(T value), List<T> updateParents(B)?) ChildPod<T, B>
Maps this Pod to a new temp Pod using the specified reducer. Optionally, provide updateParents to define how parent Pods should be updated when this Pod changes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
refresh() Future<void>
Refresh this Pod's value asynchronously and notfies any listeners after the current build phase to allow you to make state changes during the build phase.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
set(T newValue) Future<void>
Set this Pod's value asynchronously and notfies any listeners after the current build phase to allow you to make state changes during the build phase.
toString() String
A string representation of this object.
inherited
update(T updater(T oldValue)) Future<void>
Update this Pod's value asynchronously and notfies any listeners after the current build phase to allow you to make state changes during the build phase.

Operators

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

Static Methods

cast<T>(PodListenable<T> other) Pod<T>
from2<T, A, B>(Pods2<A, B> instances, T reducer(Pods2<A, B> instances), (A?, B?) updateParents(T childValue)?) ChildPod<dynamic, T>
Reduces a tuple 2 Pod - instances to a single ChildPod instance via reducer. Optionally provide updateParents to define how parent Pods should be updated when this Pod changes.
from3<T, A, B, C>(Pods3<A, B, C> instances, T reducer(Pods3<A, B, C> instances), (A?, B?, C?) updateParents(T childValue)?) ChildPod<dynamic, T>
Reduces a tuple 3 Pod - instances to a single ChildPod instance via reducer. Optionally provide updateParents to define how parent Pods should be updated when this Pod changes.
from4<T, A, B, C, D>(Pods4<A, B, C, D> instances, T reducer(Pods4<A, B, C, D> instances), (A?, B?, C?, D?) updateParents(T childValue)?) ChildPod<dynamic, T>
Reduces a tuple 4 Pod - instances to a single ChildPod instance via reducer. Optionally provide updateParents to define how parent Pods should be updated when this Pod changes.
from5<T, A, B, C, D, E>(Pods5<A, B, C, D, E> instances, T reducer(Pods5<A, B, C, D, E> instances), (A?, B?, C?, D?, E?) updateParents(T childValue)?) ChildPod<dynamic, T>
Reduces a tuple 5 Pod - instances to a single ChildPod instance via reducer. Optionally provide updateParents to define how parent Pods should be updated when this Pod changes.
from6<T, A, B, C, D, E, F>(Pods6<A, B, C, D, E, F> instances, T reducer(Pods6<A, B, C, D, E, F> instances), (A?, B?, C?, D?, E?, F?) updateParents(T childValue)?) ChildPod<dynamic, T>
Reduces a tuple 6 Pod - instances to a single ChildPod instance via reducer. Optionally provide updateParents to define how parent Pods should be updated when this Pod changes.
fromMany<A, B>(Iterable<Pod<A>> instances, B reducer(ManyPods<A> instances), Iterable<A> updateParents(B childValue)?) ChildPod<A, B>
Reduces many Pod - instances to a single ChildPod instance via reducer. Optionally provide updateParents to define how parent Pods should be updated when this Pod changes.