Merge branch 'feature/my' of http://1.95.137.212:57001/APP/FlutterApp into feature/my
This commit is contained in:
@@ -200,13 +200,21 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
/// 绑定设备
|
||||
Future<void> bindDevice(String deviceId, String deviceAlias) async {
|
||||
|
||||
emit(state.copyWith(isLoading: true, errorMessage: ''));
|
||||
try {
|
||||
final params = BindDeviceParams(deviceId, deviceAlias);
|
||||
final result = await _bindDeviceUseCase.call(params);
|
||||
result.fold(
|
||||
// 失败处理
|
||||
(failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message ?? '绑定设备失败')),
|
||||
(failure) {
|
||||
emit(state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: failure.message ?? '绑定设备失败',
|
||||
));
|
||||
// 抛出异常,携带后端返回的错误消息(如“设备不存在”)
|
||||
throw Exception(failure.message ?? '绑定设备失败');
|
||||
},
|
||||
// 成功处理(返回 int 状态码)
|
||||
(successCode) {
|
||||
if (successCode == 1) {
|
||||
@@ -219,7 +227,12 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
emit(state.copyWith(isLoading: false, errorMessage: '绑定异常:${e.toString()}'));
|
||||
// emit(state.copyWith(
|
||||
// isLoading: false,
|
||||
// errorMessage: '绑定异常:${e.toString()}',
|
||||
// ));
|
||||
// 🔥 重新抛出,传递给 UI
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user