/// 自动导入ValueNotifier拓展 export 'package:lszlgl/ext/value_notifier_ext.dart'; /// /// VM基类 abstract class BaseVM { /// 是否被销毁 bool _dispose = false; get isDispose => _dispose; /// 销毁时回调方法 void dispose() { _dispose = true; } } /// /// 数据状态装饰类 /// /// ``` /// 简单使用方法: /// // 数据 /// var user = DataStatusModel(); /// user = user.empty(); /// user = user.loading(); /// user = user.success(UserBean()); /// user = user.error('网络异常'); /// // 组件 /// setState({}); /// switch (user.status) { /// ... /// } /// ``` /// /// ``` /// 配合ValueNotifierExt使用: /// // 数据 /// final user = DataStatusModel().notifier>(); /// user.update(user.value.empty()); /// user.update(user.value.loading()); /// user.update(user.value.success(UserBean())); /// user.update(user.value.error('网络异常')); /// // 组件 /// user.builder((v) { /// switch (v.status) { /// ... /// } /// } /// ``` class DataStatusModel { /// 数据状态 DataStatus status; /// 数据内容 T? data; /// 错误信息 Object? errorData; DataStatusModel({ this.status = DataStatus.empty, this.data, this.errorData, }); /// 加载中 DataStatusModel loading({T? data, Object? error}) => DataStatusModel( status: DataStatus.loading, data: data ?? this.data, errorData: error ?? this.errorData, ); /// 加载成功 DataStatusModel success({T? data, Object? error}) => DataStatusModel( status: DataStatus.success, data: data ?? this.data, errorData: error ?? this.errorData, ); /// 无数据 DataStatusModel empty({T? data, Object? error}) => DataStatusModel( data: data ?? this.data, errorData: error ?? this.errorData, ); /// 加载失败 DataStatusModel error({T? data, Object? error}) => DataStatusModel( status: DataStatus.error, data: data ?? this.data, errorData: error ?? this.errorData, ); } /// 数据状态 enum DataStatus { /// 无数据 empty, /// 加载中 loading, /// 加载成功 success, /// 加载失败 error, }