add exception for empty conditions

This commit is contained in:
ashrafzarkanisala
2024-08-04 00:09:36 +03:00
parent 2c6275e26b
commit 61a85a77b9

View File

@ -330,6 +330,15 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
CreateSceneWithTasksEvent event, Emitter<CreateSceneState> emit) async {
emit(CreateSceneLoading());
try {
// Check for empty conditions or actions
if (event.createAutomationModel != null) {
if (event.createAutomationModel!.conditions.isEmpty) {
throw Exception('Conditions are required');
}
if (event.createAutomationModel!.actions.isEmpty) {
throw Exception('Actions are required');
}
}
dynamic response;
if (event.createSceneModel != null) {
response = event.updateScene
@ -358,8 +367,11 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
} else {
emit(const CreateSceneError(message: 'Something went wrong'));
}
} on Exception catch (e) {
emit(CreateSceneError(message: e.toString()));
} catch (e) {
emit(const CreateSceneError(message: 'Something went wrong'));
} finally {
emit(AddSceneTask(
tasksList: tasksList,
automationTasksList: automationTasksList,