Model class abstract
A base class that holds some data and allows other classes to listen to changes to that data.
In order to notify listeners that the data has changed, you must explicitly call the notifyListeners method.
Generally used in conjunction with a ScopedModel Widget, but if you do not need to pass the Widget down the tree, you can use a simple AnimatedBuilder to listen for changes and rebuild when the model notifies the listeners.
Example
class CounterModel extends Model {
int _counter = 0;
int get counter => _counter;
void increment() {
// First, increment the counter
_counter++;
// Then notify all the listeners.
notifyListeners();
}
}
- Inheritance
-
- Object
- Listenable
- Model
Constructors
- Model()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- listenerCount → int
-
Returns the number of listeners listening to this model.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
listener
will be invoked when the model changes.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void - Should be called only by Model when the model has changed.
-
removeListener(
VoidCallback listener) → void -
listener
will no longer be invoked when the model changes.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited