Files
flutterApp/lib/features/devices/presentation/bloc/device_task_state.dart
2026-09-14 12:35:20 +08:00

69 lines
2.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:equatable/equatable.dart';
import '../../domain/entities/device_task_entity.dart';
enum DeviceTaskOperationType {
none,
cancel,
pause,
recovery,
}
class DeviceTaskState extends Equatable {
final List<DeviceTaskEntity> taskPool;
final DeviceTaskEntity? currentTask;
final int? currentTaskId;
final List<DeviceTaskEntity> activeTasks; // 🔥 活跃任务列表(供用户选择)
final bool isLoading;
final String? errorMessage;
final DeviceTaskOperationType operationType;
final bool shouldShowError; // 🔥 标记是否需要显示错误弹窗
const DeviceTaskState({
this.taskPool = const [],
this.currentTask,
this.currentTaskId,
this.activeTasks = const [], // 🔥 默认空列表
this.isLoading = false,
this.errorMessage,
this.operationType = DeviceTaskOperationType.none,
this.shouldShowError = false,
});
DeviceTaskState copyWith({
List<DeviceTaskEntity>? taskPool,
DeviceTaskEntity? currentTask,
bool clearCurrentTask = false, // 🔥 显式清空 currentTask(copyWith 传 null 无法置空)
int? currentTaskId,
bool clearCurrentTaskId = false, // 🔥 显式清空 currentTaskId
List<DeviceTaskEntity>? activeTasks, // 🔥 新增
bool? isLoading,
String? errorMessage,
DeviceTaskOperationType? operationType,
bool? shouldShowError,
}) {
return DeviceTaskState(
taskPool: taskPool ?? this.taskPool,
currentTask: clearCurrentTask ? null : (currentTask ?? this.currentTask),
currentTaskId:
clearCurrentTaskId ? null : (currentTaskId ?? this.currentTaskId),
activeTasks: activeTasks ?? this.activeTasks, // 🔥 新增
isLoading: isLoading ?? this.isLoading,
errorMessage: errorMessage,
operationType: operationType ?? this.operationType,
shouldShowError: shouldShowError ?? false, // 🔥 默认重置为 false
);
}
@override
List<Object?> get props => [
taskPool,
currentTask,
currentTaskId,
activeTasks, // 🔥 新增
isLoading,
errorMessage,
operationType,
shouldShowError,
];
}