作业首页和机器状态的数据
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../domain/usecases/search_device_usecase.dart';
|
||||
import 'find_robot_state.dart';
|
||||
|
||||
/// 一键寻车 Cubit
|
||||
///
|
||||
/// 调用链:UI → FindRobotCubit → SearchDeviceUseCase → Repository → DataSource,
|
||||
/// 弹窗不再直接依赖用例或数据源。
|
||||
///
|
||||
/// 下发口径:deviceId 传设备编码(deviceName,MC700- 开头),不是数字主键 id。
|
||||
class FindRobotCubit extends Cubit<FindRobotState> {
|
||||
final SearchDeviceUseCase _searchDevice;
|
||||
|
||||
FindRobotCubit(this._searchDevice) : super(const FindRobotState());
|
||||
|
||||
/// 下发一键寻车指令(GET /iot/host/searchDevice)
|
||||
///
|
||||
/// [deviceCode] 为空时直接判定失败,不发请求(避免后端把空串当全量)。
|
||||
Future<void> startFind({required String deviceCode}) async {
|
||||
if (state.isSubmitting) return;
|
||||
|
||||
final code = deviceCode.trim();
|
||||
if (code.isEmpty) {
|
||||
emit(const FindRobotState(errorMessage: ''));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(FindRobotState(isSubmitting: true, deviceCode: code));
|
||||
|
||||
final result = await _searchDevice.execute(deviceCode: code);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(
|
||||
FindRobotState(errorMessage: failure.message, deviceCode: code),
|
||||
),
|
||||
(sent) => emit(
|
||||
FindRobotState(isSuccess: sent, deviceCode: code),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 结果已被界面消费,复位避免重复弹提示
|
||||
void reset() {
|
||||
if (state.isSubmitting) return;
|
||||
emit(const FindRobotState());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// 一键寻车指令下发状态
|
||||
///
|
||||
/// 一次性结果用 [isSuccess] / [errorMessage] 表达:
|
||||
/// [errorMessage] 非 null 即失败,空串表示只知失败、文案由 UI 套本地化提示。
|
||||
class FindRobotState extends Equatable {
|
||||
/// 请求进行中(用于拦截重复点击)
|
||||
final bool isSubmitting;
|
||||
|
||||
/// 后端已成功下发寻车指令
|
||||
final bool isSuccess;
|
||||
|
||||
/// 失败原因;null 表示尚无结果
|
||||
final String? errorMessage;
|
||||
|
||||
/// 本次操作的设备编码(MC700- 开头)
|
||||
final String? deviceCode;
|
||||
|
||||
const FindRobotState({
|
||||
this.isSubmitting = false,
|
||||
this.isSuccess = false,
|
||||
this.errorMessage,
|
||||
this.deviceCode,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [isSubmitting, isSuccess, errorMessage, deviceCode];
|
||||
}
|
||||
Reference in New Issue
Block a user