PropertyChangeNotifier<T extends Object> class

A backwards-compatible implementation of ChangeNotifier that allows implementers to provide more granular information to listeners about what specific property was changed. This lets listeners be much more efficient when responding to model changes. Any number of listeners can subscribe to any number of properties.

Like ChangeNotifier, is optimized for small numbers (one or two) of listeners. It is O(N) for adding and removing listeners and O(N²) for dispatching notifications (where N is the number of listeners).

T is the type of the property name and is usually String but can be an Enum or any type that subclasses Object. To work correctly, T must implement operator== and hashCode.

Inheritance

Constructors

PropertyChangeNotifier()

Properties

hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Reimplemented from ChangeNotifier. Clients should not depend on this value for their behavior, because having one listener's logic change when another listener happens to start or stop listening will lead to extremely hard-to-track bugs. Subclasses might use this information to determine whether to do any work when there are no listeners, however; for example, resuming a Stream when a listener is added and pausing it when a listener is removed.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(Function listener, [Iterable<T>? properties]) → void
Registers listener for the given properties. listener must not be null. If properties is null or empty, listener will be added as a global listener, meaning it will be invoked for all property changes. This is the default behavior of ChangeNotifier. listener must either accept no parameters or a single T parameter. If listener accepts a T parameter, it will be invoked with the property name provided by notifyListeners. The same listener can be added for multiple properties. Adding the same listener for the same property is a no-op. Adding a listener for a non-existent property will not fail, but is functionally pointless.
override
dispose() → void
Reimplemented from ChangeNotifier. 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 and removeListener will throw after the object is disposed).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners([T? property]) → void
Notifies the appropriate listeners that property was changed. Implementers should ideally provide a property parameter. It is only optional for backwards compatibility with ChangeNotifier. Global listeners will be notified every time, even if property is null. Listeners for specific properties will only be notified if property is equal (operator==) to one of those properties. If property is not null, must be a single instance of T (typically a String).
override
removeListener(Function listener, [Iterable<T>? properties]) → void
Removes listener for the given properties. listener must not be null. If properties is null or empty, listener will be removed as a global listener. Removing a listener will not affect any other properties listeners is registered for. Removing a non-existent listener is no-op. Removing a listener for a non-existent property will not fail.
override
toString() String
A string representation of this object.
inherited

Operators

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