Model class abstract
持有数据并允许其他类监听数据变化的基类
若要通知监听器数据发生了变化,必须显式调用notifyListeners方法
通常与EasyModel Widget结合使用,若不需要将Widget传递到widget树中, 可以使用简单的AnimatedBuilder来监听变化,并在模型通知监听器时重建
示例
class CounterModel extends Model {
int _counter = 0;
int get counter => _counter;
void increment() {
_counter++;
notifyListeners();
}
}
- Inheritance
-
- Object
- Listenable
- Model
- Implementers
Constructors
- Model()
Properties
- hashCode → int
-
获取模型hashCode
no setteroverride
- isDisposed → bool
-
是否已销毁
no setter
- listenerCount → int
-
获取监听器数量
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- version → int
-
获取版本号
no setter
Methods
-
addListener(
VoidCallback listener) → void -
添加监听器
override
-
dispose(
) → void - 销毁模型
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void - 通知所有监听器
-
refresh(
{bool force = false}) → void - 刷新Model,触发监听器通知
-
removeListener(
VoidCallback listener) → void -
移除监听器
override
-
toReactive<
T> (T extractor()) → Reactive< T> - 转换为Reactive
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited