From 61a85a77b9795ca4d588ebcca03bd19deee10255 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 00:09:36 +0300 Subject: [PATCH] add exception for empty conditions --- .../scene/bloc/create_scene/create_scene_bloc.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index cfbf305..4700f8f 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -330,6 +330,15 @@ class CreateSceneBloc extends Bloc CreateSceneWithTasksEvent event, Emitter 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 } 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,