ValueNotifier
live Holds a single observable value and notifies listeners when it changes. Use this to share reactive state between parts of the UI that are not directly related in the element tree. Pair with ValueListenableBuilder to rebuild a subtree whenever the value changes.
Constructor
ValueNotifier
Creates a new notifier with the given initial value.
| Parameter | Description |
|---|---|
initialValue | The initial value. |
Properties
Value
The current value. Setting this to a new value notifies all listeners. Setting it to a value that compares equal to the current value is a no-op.
Methods
AddListener
Registers a callback that is invoked whenever the value changes. The callback is invoked synchronously during the value assignment.
| Parameter | Description |
|---|---|
listener | The callback to invoke on change. |
Dispose
Disposes this notifier, clearing all listeners and preventing further use.
RemoveListener
Removes a previously registered listener. If the listener was added more than once, only the first occurrence is removed. Does nothing if the listener is not found.
| Parameter | Description |
|---|---|
listener | The callback to remove. |