HiveBoxMx<T> mixin

使用 with 混入本类, 以添加Hive持久化支持 调用dispose 不会移除本地存储的数据 onCreate 设置的初始化数据仅在本地数据为null时生效

Superclass constraints

Properties

hashCode int
The hash code for this object.
no setterinherited
initValue → T?
initValue 初始值 如果不想设置初始值, 请return null; 如果要需要异步初始化, 请return null, 并覆写onCreate 函数
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
storage String
no setter
stream Stream<T>
no setterinherited
subject StreamController<T>
no setterinherited
value → T
no setterinherited
valueOrNull → T?
如果没有初始值, 则value可能为null,使用valueOrNull避免抛出异常
no setterinherited

Methods

combineStream(List<BaseHiveState>? combines) → CombineLatestStream<dynamic, List>
合并多个HiveState, 任意一个HiveState更新,都会产生新的event 返回值: List, 按顺序返回每一个Stream的最新的值; 由于每个Stream的类型可能不同, 所以类型为List
inherited
dispose() → void
============== 以下是高级功能, 一般情况下无需使用 ============== 释放内存
inherited
fromJson(String value) → T
logger(String message, {DateTime? time, int? sequenceNumber, int level = 0, String? name, Zone? zone, Object? error, StackTrace? stackTrace}) → dynamic
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCreate({T? initValue}) StreamController<T>
通过覆写onCreate,可以实现在首次创建subject时设置初始数据T实例 但如果初始值不是固定值, 则需要通过BaseHiveState.init设置初始值T实例 注意: 一般情况下, 是在Widget的initState方法中调用 put 值进行初始化;
override
openBox() FutureOr<Box<String>>
全局单例: box固定为String 整个App的所有HiveState继承类,只需要openBox一次;
openHiveBox<E>(String name) Future<Box<E>>
通过覆写本函数,实现
put(T value) BaseHiveState<T>
每次更新状态, 都将保存到box中
override
putError(Object e, [StackTrace? s]) BaseHiveState<T>
inherited
toJson(T value) String
toString() String
A string representation of this object.
inherited
update(FutureOr<T> update(T old), {dynamic onError(Object e, StackTrace s)?}) Future<void>
执行一个异步操作, 并更新状态 不建议对本方法进行二次包装, 因此返回值强制为 void
inherited
updateOrNull(FutureOr<T> update(T? old), {dynamic onError(Object e, StackTrace s)?}) Future<void>
if State init value is null, you can use updateOrNull
inherited
valueToString(T? value) String
putError中, 将会打印model值value 覆写本函数, 返回需要打印的内容
inherited

Operators

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