DKStateEvent<T> class
sealed
DKStateEvent - 用于一次性事件操作的状态管理
适用场景:
- POST/PUT/DELETE 请求
- 提交操作(表单提交、按钮点击)
- 一次性事件(显示 Snackbar、导航跳转)
- 配合 StreamController 使用
通用逻辑请使用:
DKStateEventHelper工具类提供的静态方法DKStateEventFlutterExtension提供的扩展方法(用于 StreamController)
例如:
// 方式1: 使用扩展方法(推荐)
final submitEvent = StreamController<DKStateEvent<String>>();
submitEvent.triggerEvent(() async {
await Future.delayed(Duration(seconds: 2));
return 'Success';
});
final subscription = submitEvent.listenEvent(
onLoading: () => print('Loading...'),
onSuccess: (data, message) => print('Success: $data'),
onError: (message, error, stackTrace) => print('Error: $message'),
);
// 方式2: 使用工具类
await DKStateEventHelper.triggerEvent<String>(
onStateChange: (state) => controller.add(state),
event: () async => await fetchData(),
);
Properties
- data → T
-
no setter
- errorMessage → String
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isError → bool
-
no setter
- isIdle → bool
-
no setter
- isLoading → bool
-
no setter
- isSuccess → bool
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited