From 84d909a10a8ff03908240e2937747351e5779b03 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sat, 3 Aug 2024 15:15:09 +0300 Subject: [PATCH 01/10] fix last testing bugs --- .../devices/view/widgets/scene_listview.dart | 12 ++- .../bloc/create_scene/create_scene_bloc.dart | 40 +++++----- .../scene/helper/scene_logic_helper.dart | 3 +- .../view/smart_automation_select_route.dart | 9 ++- .../scene/widgets/bottom_sheet_widget.dart | 5 +- .../if_then_containers/then_container.dart | 4 +- .../smart_automation_list.dart | 76 +++++++++++++------ .../smart_enable_autoamtion.dart | 5 +- 8 files changed, 99 insertions(+), 55 deletions(-) diff --git a/lib/features/devices/view/widgets/scene_listview.dart b/lib/features/devices/view/widgets/scene_listview.dart index d825c6b..e0065cc 100644 --- a/lib/features/devices/view/widgets/scene_listview.dart +++ b/lib/features/devices/view/widgets/scene_listview.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; -import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart'; -import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart'; import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart'; import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart'; import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart'; @@ -29,7 +27,6 @@ class SceneListview extends StatelessWidget { itemCount: scenes.length, itemBuilder: (context, index) { final scene = scenes[index]; - final isLoading = loadingSceneId == scene.id; return Container( padding: const EdgeInsets.only(right: 10), child: DefaultContainer( @@ -43,8 +40,15 @@ class SceneListview extends StatelessWidget { sceneName: scene.name, ), ); + context + .read() + .add(const SmartSceneClearEvent()); + BlocProvider.of(context) - .add(FetchSceneTasksEvent(sceneId: scene.id)); + .add(const SceneTypeEvent(CreateSceneEnum.tabToRun)); + BlocProvider.of(context).add( + FetchSceneTasksEvent( + sceneId: scene.id, isAutomation: false)); }, child: SizedBox( width: MediaQuery.of(context).size.width * 0.4, 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 915d8af..5db632d 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -95,25 +95,27 @@ class CreateSceneBloc extends Bloc // Check and update if the task exists in tempTasksList for (var element in tempTasksList) { - var updatedElement = element.copyWith( - operationName: event.operation, - deviceName: event.deviceName, - icon: event.icon, - code: event.deviceControlModel.code ?? '', - deviceId: event.deviceId, - functionValue: event.deviceControlModel.value, - operationDialogType: event.operationType, - operationalValues: [ - SceneOperationalValue( - value: event.deviceControlModel.value, - icon: '', - ), - ], - ); - tempTasksList[tempTasksList.indexOf(element)] = updatedElement; - selectedValues[updatedElement.code] = event.deviceControlModel.value; - updated = true; - break; + if (element.code == event.deviceControlModel.code) { + var updatedElement = element.copyWith( + operationName: event.operation, + deviceName: event.deviceName, + icon: event.icon, + code: event.deviceControlModel.code ?? '', + deviceId: event.deviceId, + functionValue: event.deviceControlModel.value, + operationDialogType: event.operationType, + operationalValues: [ + SceneOperationalValue( + value: event.deviceControlModel.value, + icon: '', + ), + ], + ); + tempTasksList[tempTasksList.indexOf(element)] = updatedElement; + selectedValues[updatedElement.code] = event.deviceControlModel.value; + updated = true; + break; + } } if (!updated) { diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 35dea80..26ef64b 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -17,7 +17,8 @@ mixin SceneLogicHelper { bool isOnlyDelayOrDelayLast(List tasks) { final lastTask = tasks.last; return tasks.every((task) => task.code == 'delay') || - lastTask.code == 'delay'; + lastTask.code == 'delay' || + lastTask.deviceId == 'delay'; } void handleSaveButtonPress( diff --git a/lib/features/scene/view/smart_automation_select_route.dart b/lib/features/scene/view/smart_automation_select_route.dart index 5126a0d..13a5ad9 100644 --- a/lib/features/scene/view/smart_automation_select_route.dart +++ b/lib/features/scene/view/smart_automation_select_route.dart @@ -19,6 +19,7 @@ class SmartAutomationSelectView extends StatelessWidget { @override Widget build(BuildContext context) { final sceneType = context.read().sceneType; + final sceneId = ModalRoute.of(context)!.settings.arguments as String; return DefaultScaffold( title: "Select Smart Scene", padding: const EdgeInsets.only(top: 24), @@ -41,7 +42,8 @@ class SmartAutomationSelectView extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Visibility( - visible: sceneType.name == CreateSceneEnum.deviceStatusChanges.name, + visible: sceneType.name == + CreateSceneEnum.deviceStatusChanges.name, child: SceneListTile( assetPath: Assets.handClickIcon, titleString: "Tap To Run", @@ -58,7 +60,8 @@ class SmartAutomationSelectView extends StatelessWidget { ), ), Visibility( - visible: sceneType.name == CreateSceneEnum.deviceStatusChanges.name, + visible: sceneType.name == + CreateSceneEnum.deviceStatusChanges.name, child: const Divider( color: ColorsManager.dividerColor, ), @@ -73,7 +76,7 @@ class SmartAutomationSelectView extends StatelessWidget { ), onPressed: () { context.customBottomSheet( - child: const SmartEnableAutomation(), + child: SmartEnableAutomation(automationId: sceneId), ); }, ), diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 518ef86..163638b 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -17,7 +17,9 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class CustomBottomSheetWidget extends StatelessWidget { const CustomBottomSheetWidget({ super.key, + required this.sceneId, }); + final String sceneId; @override Widget build(BuildContext context) { @@ -68,7 +70,8 @@ class CustomBottomSheetWidget extends StatelessWidget { color: ColorsManager.greyColor, ), onPressed: () { - Navigator.pushNamed(context, Routes.smartAutomationSelectRoute); + Navigator.pushNamed(context, Routes.smartAutomationSelectRoute, + arguments: sceneId); }, ), SceneListTile( diff --git a/lib/features/scene/widgets/if_then_containers/then_container.dart b/lib/features/scene/widgets/if_then_containers/then_container.dart index 3b322e4..1610e50 100644 --- a/lib/features/scene/widgets/if_then_containers/then_container.dart +++ b/lib/features/scene/widgets/if_then_containers/then_container.dart @@ -47,7 +47,7 @@ class ThenDefaultContainer extends StatelessWidget { return GestureDetector( onTap: isClickable ? () => context.customBottomSheet( - child: const CustomBottomSheetWidget(), + child: CustomBottomSheetWidget(sceneId:sceneId), ) : null, child: SvgPicture.asset( @@ -99,7 +99,7 @@ class ThenDefaultContainer extends StatelessWidget { builder: (context) => const CreateSceneView())); } else { context.customBottomSheet( - child: const CustomBottomSheetWidget(), + child: CustomBottomSheetWidget(sceneId: sceneId,), ); } }, diff --git a/lib/features/scene/widgets/select_smart_scene/smart_automation_list.dart b/lib/features/scene/widgets/select_smart_scene/smart_automation_list.dart index fad1025..66d9df0 100644 --- a/lib/features/scene/widgets/select_smart_scene/smart_automation_list.dart +++ b/lib/features/scene/widgets/select_smart_scene/smart_automation_list.dart @@ -15,15 +15,19 @@ class SmartSceneSelectAutomationList extends StatefulWidget { const SmartSceneSelectAutomationList({ super.key, required this.automationList, + required this.automationId, }); final List automationList; + final String automationId; @override - State createState() => _SmartSceneSelectAutomationListState(); + State createState() => + _SmartSceneSelectAutomationListState(); } -class _SmartSceneSelectAutomationListState extends State { +class _SmartSceneSelectAutomationListState + extends State { final List colorList = _generateDarkColors(100); static List _generateDarkColors(int count) { @@ -31,7 +35,8 @@ class _SmartSceneSelectAutomationListState extends State[]; while (colors.length < count) { - final color = Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0); + final color = + Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0); if (_isDark(color)) { colors.add(color); } @@ -40,12 +45,17 @@ class _SmartSceneSelectAutomationListState extends State e.id != widget.automationId.toString()) + .toList(); return Column( mainAxisSize: MainAxisSize.min, children: [ @@ -70,7 +80,8 @@ class _SmartSceneSelectAutomationListState extends State().add(const SmartSceneClearEvent()); + context + .read() + .add(const SmartSceneClearEvent()); Navigator.pop(context); }, ); }, label: BodyMedium( text: _capitalizeFirst(descriptionSelected), - style: context.bodyMedium.copyWith(color: ColorsManager.greyColor), + style: context.bodyMedium + .copyWith(color: ColorsManager.greyColor), ), icon: const Icon( Icons.arrow_forward_ios_rounded, @@ -162,7 +179,9 @@ class _SmartSceneSelectAutomationListState extends State().add(const SmartSceneClearEvent()); + context + .read() + .add(const SmartSceneClearEvent()); Navigator.pop(context); }, ); @@ -198,10 +217,12 @@ class EnableDisableAutomationDialog extends StatefulWidget { final String type; @override - State createState() => _EnableDisableAutomationDialogState(); + State createState() => + _EnableDisableAutomationDialogState(); } -class _EnableDisableAutomationDialogState extends State { +class _EnableDisableAutomationDialogState + extends State { String? groupValue; final List values = [ SceneOperationalValue( @@ -219,14 +240,16 @@ class _EnableDisableAutomationDialogState extends State().add(SmartSceneEnableEvent(SmartSceneEnable( - entityId: widget.automationId, - actionExecutor: groupValue!, - sceneORAutomationName: widget.sceneORAutomationName, - type: widget.type, - isAutomation: true))); + context.read().add(SmartSceneEnableEvent( + SmartSceneEnable( + entityId: widget.automationId, + actionExecutor: groupValue!, + sceneORAutomationName: widget.sceneORAutomationName, + type: widget.type, + isAutomation: true))); } @override @@ -252,11 +275,14 @@ class _EnableDisableAutomationDialogState extends State().add(SmartSceneEnableEvent( + context + .read() + .add(SmartSceneEnableEvent( SmartSceneEnable( entityId: widget.automationId, actionExecutor: value!, - sceneORAutomationName: widget.sceneORAutomationName, + sceneORAutomationName: + widget.sceneORAutomationName, type: widget.type, isAutomation: true), )); @@ -266,7 +292,9 @@ class _EnableDisableAutomationDialogState extends State().add(SmartSceneEnableEvent( + context + .read() + .add(SmartSceneEnableEvent( SmartSceneEnable( entityId: widget.automationId, actionExecutor: operation.value, diff --git a/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart b/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart index d4684f5..6560c63 100644 --- a/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart +++ b/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart @@ -10,7 +10,9 @@ import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/utils/context_extension.dart'; class SmartEnableAutomation extends StatelessWidget { - const SmartEnableAutomation({super.key}); + const SmartEnableAutomation({super.key, required this.automationId}); + + final String automationId; @override Widget build(BuildContext context) { @@ -29,6 +31,7 @@ class SmartEnableAutomation extends StatelessWidget { } if (state is SceneLoaded) { return SmartSceneSelectAutomationList( + automationId: automationId, automationList: state.automationList); } return const SizedBox.shrink(); From 2c6275e26b721b58715a496fe10323811cdc78cf Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sat, 3 Aug 2024 23:48:56 +0300 Subject: [PATCH 02/10] solve bugs --- .../scene/bloc/create_scene/create_scene_bloc.dart | 13 ++----------- .../bloc/effective_period/effect_period_bloc.dart | 7 +++++++ .../bloc/effective_period/effect_period_event.dart | 6 ++++++ .../alert_dialogs/alert_dialog_slider_steps.dart | 9 +++++++++ .../if_then_containers/then_added_tasks.dart | 4 ++-- 5 files changed, 26 insertions(+), 13 deletions(-) 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 5db632d..cfbf305 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -414,19 +414,10 @@ class CreateSceneBloc extends Bloc NavigationService.navigatorKey.currentContext!) .add(SetCustomTime(effectiveTime!.start, effectiveTime!.end)); - // Reset all days to not selected before toggling + // Set the days directly from the API response BlocProvider.of( NavigationService.navigatorKey.currentContext!) - .add(ResetDays()); - - // Iterate over the loops and toggle each day - for (int i = 0; i < effectiveTime!.loops.length; i++) { - if (effectiveTime!.loops[i] == '1') { - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) - .add(ToggleDay(_getDayFromIndex(i))); - } - } + .add(SetDays(response.effectiveTime?.loops ?? '1111111')); emit(AddSceneTask( automationTasksList: automationTasksList, diff --git a/lib/features/scene/bloc/effective_period/effect_period_bloc.dart b/lib/features/scene/bloc/effective_period/effect_period_bloc.dart index ea2c501..551c06b 100644 --- a/lib/features/scene/bloc/effective_period/effect_period_bloc.dart +++ b/lib/features/scene/bloc/effective_period/effect_period_bloc.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:bloc/bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; @@ -14,6 +16,7 @@ class EffectPeriodBloc extends Bloc { on(_onSetCustomTime); on(_onResetEffectivePeriod); on(_onResetDays); + on(_setAllDays); } void _onSetPeriod(SetPeriod event, Emitter emit) { @@ -120,4 +123,8 @@ class EffectPeriodBloc extends Bloc { const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; return days.indexOf(day); } + + FutureOr _setAllDays(SetDays event, Emitter emit) { + emit(state.copyWith(selectedDaysBinary: event.daysBinary)); + } } diff --git a/lib/features/scene/bloc/effective_period/effect_period_event.dart b/lib/features/scene/bloc/effective_period/effect_period_event.dart index c628983..cd1a9c0 100644 --- a/lib/features/scene/bloc/effective_period/effect_period_event.dart +++ b/lib/features/scene/bloc/effective_period/effect_period_event.dart @@ -42,3 +42,9 @@ class ResetDays extends EffectPeriodEvent { @override List get props => []; } + +class SetDays extends EffectPeriodEvent { + final String daysBinary; + + const SetDays(this.daysBinary); +} diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart index 3e986e7..18fdb05 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart @@ -57,6 +57,15 @@ class _AlertDialogSliderStepsState extends State { } setState(() {}); + + context.read().add( + SelectedValueEvent( + value: _deNormalizeValue(groupValue), + code: widget.taskItem.code, + isAutomation: widget.isAutomation, + comparator: _indexToComparator(selectedToggleIndex), + ), + ); } double _normalizeValue(dynamic value) { diff --git a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart index 1af98c4..131f810 100644 --- a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart +++ b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart @@ -48,9 +48,9 @@ class ThenAddedTasksContainer extends StatelessWidget "${duration.inHours}h ${duration.inMinutes.remainder(60)}m "; } else if (taskItem.code.contains('temp_set') || taskItem.code.contains('temp_current')) { - if (taskItem.functionValue != null || taskItem.functionValue != 0) { + if ((taskItem.functionValue != null || taskItem.functionValue != 0)) { operationValue = - '${((taskItem.functionValue / 10) as double).round().toString()}°C'; + '${((taskItem.functionValue / 10) as double).toStringAsFixed(1)}°C'; } else { operationValue = '0°C'; } From 61a85a77b9795ca4d588ebcca03bd19deee10255 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 00:09:36 +0300 Subject: [PATCH 03/10] 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, From 376032923663e0a9ec11d40df3311b28973aff8b Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 16:41:13 +0300 Subject: [PATCH 04/10] push fixes --- .../bloc/create_scene/create_scene_bloc.dart | 55 +++-- .../scene/helper/scene_logic_helper.dart | 21 ++ .../helper/scene_operations_data_helper.dart | 196 +++++++++++------- .../scene/model/scene_static_function.dart | 15 +- .../scene/view/device_functions_view.dart | 4 +- lib/features/scene/view/scene_tasks_view.dart | 3 + .../alert_dialog_slider_steps.dart | 10 +- .../alert_dialog_temperature_body.dart | 9 +- .../scene/widgets/bottom_sheet_widget.dart | 2 +- .../widgets/create_scene_save_button.dart | 10 +- .../if_then_containers/then_added_tasks.dart | 13 +- .../if_then_containers/then_container.dart | 6 +- .../widgets/scene_view_widget/scene_item.dart | 25 +-- lib/utils/helpers/snack_bar.dart | 2 +- 14 files changed, 236 insertions(+), 135 deletions(-) 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 4700f8f..104396f 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -250,6 +250,15 @@ class CreateSceneBloc extends Bloc break; } } + for (int i = 0; i < tasksList.length; i++) { + if (tasksList[i].code == event.code) { + tasksList[i] = tasksList[i].copyWith( + comparator: event.comparator ?? '==', + functionValue: event.value, + ); + break; + } + } } else { selectedValues[event.code] = event.value; } @@ -330,15 +339,6 @@ 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 @@ -367,11 +367,8 @@ 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, @@ -397,6 +394,18 @@ class CreateSceneBloc extends Bloc emit(CreateSceneLoading()); try { + tasksList.clear(); + tempTasksList.clear(); + selectedValues.clear(); + automationTasksList.clear(); + automationTempTasksList.clear(); + automationSelectedValues.clear(); + automationComparatorValues.clear(); + effectiveTime = + EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'); + sceneType = CreateSceneEnum.none; + conditionRule = 'or'; + final response = event.isAutomation ? await SceneApi.getAutomationDetails(event.sceneId) : await SceneApi.getSceneDetails(event.sceneId); @@ -421,16 +430,16 @@ class CreateSceneBloc extends Bloc ) : EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'); - // Set Custom Time and reset days first - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) - .add(SetCustomTime(effectiveTime!.start, effectiveTime!.end)); - // Set the days directly from the API response BlocProvider.of( NavigationService.navigatorKey.currentContext!) .add(SetDays(response.effectiveTime?.loops ?? '1111111')); + // Set Custom Time and reset days first + BlocProvider.of( + NavigationService.navigatorKey.currentContext!) + .add(SetCustomTime(effectiveTime!.start, effectiveTime!.end)); + emit(AddSceneTask( automationTasksList: automationTasksList, tasksList: tasksList, @@ -536,6 +545,14 @@ class CreateSceneBloc extends Bloc break; } } + for (var i = 0; i < tasksList.length; i++) { + if (tasksList[i].uniqueCustomId == event.taskId) { + tasksList[i] = tasksList[i].copyWith( + functionValue: event.newValue, + ); + break; + } + } } else { for (var i = 0; i < tasksList.length; i++) { if (tasksList[i].uniqueCustomId == event.taskId) { @@ -571,7 +588,7 @@ class CreateSceneBloc extends Bloc FutureOr _sceneTypeEvent( SceneTypeEvent event, Emitter emit) { - emit(CreateSceneInitial()); + // emit(CreateSceneInitial()); if (event.type == CreateSceneEnum.tabToRun) { sceneType = CreateSceneEnum.tabToRun; @@ -581,7 +598,7 @@ class CreateSceneBloc extends Bloc sceneType = CreateSceneEnum.none; } - emit(SceneTypeState(event.type)); + // emit(SceneTypeState(event.type)); } FutureOr _onEffectiveTimeEvent( diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 26ef64b..1bda43d 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -42,6 +42,27 @@ mixin SceneLogicHelper { ); return; } + if (isAutomation == true && conditions.isEmpty) { + context.showCustomSnackbar( + message: 'Conditions Must not be empty!', + icon: const Icon( + Icons.error, + color: Colors.red, + ), + ); + return; + } + + if (isAutomation == true && actions.isEmpty) { + context.showCustomSnackbar( + message: 'Actions Must not be empty!', + icon: const Icon( + Icons.error, + color: Colors.red, + ), + ); + return; + } if (isAutomation) { final createAutomationModel = CreateAutomationModel( diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index e2bb943..0e7fb33 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -247,10 +247,12 @@ mixin SceneOperationsDataHelper { Action action, bool isAutomation, { String? comparator, + String? uniqueCustomId, }) { final executorProperty = action.executorProperty; - final Map + final Map functionMap = { 'sensitivity': _createSensitivityFunction, 'normal_open_switch': _createNormalOpenSwitchFunction, @@ -294,7 +296,7 @@ mixin SceneOperationsDataHelper { final functionCode = executorProperty?.functionCode ?? ''; final createFunction = functionMap[functionCode]; if (createFunction != null) { - return createFunction(action, isAutomation, comparator); + return createFunction(action, isAutomation, comparator, uniqueCustomId); } else { throw ArgumentError('Unsupported function code: $functionCode'); } @@ -309,9 +311,11 @@ mixin SceneOperationsDataHelper { List operationalValues, bool isAutomation, [ String? comparator, + String? uniqueCustomId, ]) { final functionValue = action.executorProperty?.functionValue; return SceneStaticFunction( + uniqueCustomId: uniqueCustomId, deviceId: action.entityId, deviceName: deviceName, deviceIcon: icon, @@ -325,8 +329,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createSensitivityFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createSensitivityFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Presence Sensor', @@ -338,11 +342,12 @@ mixin SceneOperationsDataHelper { isAutomation ? _createIntegerStepsOptions() : _createSensitivityOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createNormalOpenSwitchFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createNormalOpenSwitchFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -352,6 +357,7 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } @@ -394,8 +400,8 @@ mixin SceneOperationsDataHelper { ]; } - SceneStaticFunction _createUnlockFingerprintFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createUnlockFingerprintFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -405,11 +411,12 @@ mixin SceneOperationsDataHelper { _createFingerprintUnlockOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createUnlockPasswordFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createUnlockPasswordFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -419,11 +426,12 @@ mixin SceneOperationsDataHelper { _createPasswordUnlockOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createUnlockCardFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createUnlockCardFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -433,11 +441,12 @@ mixin SceneOperationsDataHelper { _createCardUnlockOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createAlarmLockFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createAlarmLockFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -447,11 +456,12 @@ mixin SceneOperationsDataHelper { _createLockAlarmOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createUnlockRequestFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createUnlockRequestFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -461,11 +471,12 @@ mixin SceneOperationsDataHelper { _createUnlockRequestOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createResidualElectricityFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createResidualElectricityFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -475,11 +486,12 @@ mixin SceneOperationsDataHelper { _createResidualElectricityOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createReverseLockFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createReverseLockFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -489,11 +501,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createUnlockAppFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createUnlockAppFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -503,11 +516,12 @@ mixin SceneOperationsDataHelper { _createUnlockAppOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createHijackFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createHijackFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -517,11 +531,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createDoorbellFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createDoorbellFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -531,11 +546,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createUnlockTemporaryFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createUnlockTemporaryFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -545,11 +561,12 @@ mixin SceneOperationsDataHelper { _createTemporaryPasswordUnlockOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createFarDetectionFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createFarDetectionFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -559,11 +576,12 @@ mixin SceneOperationsDataHelper { _createFarDetectionOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createMotionSensitivityFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createMotionSensitivityFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -573,11 +591,12 @@ mixin SceneOperationsDataHelper { _createSensitivityOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createMotionlessSensitivityFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createMotionlessSensitivityFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -587,11 +606,12 @@ mixin SceneOperationsDataHelper { _createSensitivityOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createIndicatorFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createIndicatorFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -601,11 +621,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createPresenceTimeFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createPresenceTimeFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -615,11 +636,12 @@ mixin SceneOperationsDataHelper { _createCountdownOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createPresenceStateFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createPresenceStateFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -629,11 +651,12 @@ mixin SceneOperationsDataHelper { _createPresenceStateOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createDisCurrentFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createDisCurrentFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -645,11 +668,12 @@ mixin SceneOperationsDataHelper { _createCurrentDistanceOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createIlluminanceValueFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createIlluminanceValueFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -659,11 +683,12 @@ mixin SceneOperationsDataHelper { _createIlluminanceValueOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createCheckingResultFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createCheckingResultFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -673,11 +698,12 @@ mixin SceneOperationsDataHelper { _createSelfTestResultOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createSwitchFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createSwitchFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -687,11 +713,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createTempSetFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createTempSetFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -705,11 +732,12 @@ mixin SceneOperationsDataHelper { : _createTemperatureOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createTempCurrentFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createTempCurrentFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -719,11 +747,12 @@ mixin SceneOperationsDataHelper { _createCurrentTemperatureOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createModeFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createModeFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -733,11 +762,12 @@ mixin SceneOperationsDataHelper { _createAcModeOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createLevelFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createLevelFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -747,11 +777,12 @@ mixin SceneOperationsDataHelper { _createFanSpeedOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createChildLockFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createChildLockFunction(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -761,11 +792,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createSwitch1Function( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createSwitch1Function(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -775,11 +807,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createSwitch2Function( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createSwitch2Function(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -789,11 +822,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createSwitch3Function( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createSwitch3Function(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -803,11 +837,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createCountdown1Function( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createCountdown1Function(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -821,11 +856,12 @@ mixin SceneOperationsDataHelper { : _createCountdownOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createCountdown2Function( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createCountdown2Function(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -839,11 +875,12 @@ mixin SceneOperationsDataHelper { : _createCountdownOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createCountdown3Function( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createCountdown3Function(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -857,11 +894,12 @@ mixin SceneOperationsDataHelper { : _createCountdownOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createSwitchAlarmSoundFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createSwitchAlarmSoundFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Gateway', @@ -871,11 +909,12 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createMasterStateFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createMasterStateFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Gateway', @@ -885,11 +924,12 @@ mixin SceneOperationsDataHelper { _createMasterStateOptions(), isAutomation, comparator, + uniqueCustomId, ); } - SceneStaticFunction _createFactoryResetFunction( - Action action, bool isAutomation, String? comparator) { + SceneStaticFunction _createFactoryResetFunction(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Gateway', @@ -899,6 +939,7 @@ mixin SceneOperationsDataHelper { _createOnOffOptions(), isAutomation, comparator, + uniqueCustomId, ); } @@ -1181,6 +1222,7 @@ mixin SceneOperationsDataHelper { if (deviceId.contains('delay')) { return [ SceneStaticFunction( + uniqueCustomId: taskItem.uniqueCustomId, deviceId: taskItem.deviceId, deviceName: 'delay', deviceIcon: Assets.delay, @@ -1202,6 +1244,7 @@ mixin SceneOperationsDataHelper { if (taskItem.code == CreateSceneEnum.smartSceneSelect.name) { return [ SceneStaticFunction( + uniqueCustomId: taskItem.uniqueCustomId, deviceId: taskItem.deviceId, deviceName: taskItem.deviceName.toString(), deviceIcon: taskItem.operationName == 'automation' @@ -1241,6 +1284,7 @@ mixin SceneOperationsDataHelper { ), isAutomation, comparator: taskItem.comparator, + uniqueCustomId: taskItem.uniqueCustomId, ), ]; } diff --git a/lib/features/scene/model/scene_static_function.dart b/lib/features/scene/model/scene_static_function.dart index f73e130..8644f88 100644 --- a/lib/features/scene/model/scene_static_function.dart +++ b/lib/features/scene/model/scene_static_function.dart @@ -11,7 +11,7 @@ class SceneStaticFunction { final List operationalValues; final String deviceId; final String operationName; - final String uniqueCustomId; + final String? uniqueCustomId; final dynamic functionValue; final String? deviceIcon; final OperationDialogType operationDialogType; @@ -28,7 +28,8 @@ class SceneStaticFunction { this.deviceIcon, required this.operationDialogType, this.comparator, - }) : uniqueCustomId = const Uuid().v4(); + String? uniqueCustomId, + }) : uniqueCustomId = uniqueCustomId ?? const Uuid().v4(); SceneStaticFunction copyWith({ String? icon, @@ -42,6 +43,7 @@ class SceneStaticFunction { String? deviceName, OperationDialogType? operationDialogType, String? comparator, + String? uniqueCustomId, }) { return SceneStaticFunction( icon: icon ?? this.icon, @@ -54,6 +56,7 @@ class SceneStaticFunction { deviceIcon: deviceIcon ?? this.deviceIcon, operationDialogType: operationDialogType ?? this.operationDialogType, comparator: comparator ?? this.comparator, + uniqueCustomId: uniqueCustomId ?? const Uuid().v4(), ); } @@ -68,7 +71,8 @@ class SceneStaticFunction { 'functionValue': functionValue, 'deviceIcon': deviceIcon, 'operationDialogType': operationDialogType.name, - 'comparator': comparator + 'comparator': comparator, + 'uniqueCustomId': uniqueCustomId, }; } @@ -88,6 +92,7 @@ class SceneStaticFunction { ? OperationDialogType.values.byName(map['operationDialogType']) : OperationDialogType.none, comparator: map['comparator'], + uniqueCustomId: map['uniqueCustomId'] ?? const Uuid().v4(), ); } @@ -98,7 +103,7 @@ class SceneStaticFunction { @override String toString() { - return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName, functionValue: $functionValue, deviceIcon: $deviceIcon, operationDialogType: $operationDialogType, comparator: $comparator)'; + return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName, functionValue: $functionValue, deviceIcon: $deviceIcon, operationDialogType: $operationDialogType, comparator: $comparator, uniqueCustomId: $uniqueCustomId)'; } @override @@ -113,6 +118,7 @@ class SceneStaticFunction { other.functionValue == functionValue && other.deviceIcon == deviceIcon && other.comparator == comparator && + other.uniqueCustomId == uniqueCustomId && other.operationDialogType == operationDialogType && listEquals(other.operationalValues, operationalValues) && other.deviceId == deviceId; @@ -128,6 +134,7 @@ class SceneStaticFunction { functionValue.hashCode ^ deviceIcon.hashCode ^ comparator.hashCode ^ + uniqueCustomId.hashCode ^ operationDialogType.hashCode ^ operationalValues.hashCode; } diff --git a/lib/features/scene/view/device_functions_view.dart b/lib/features/scene/view/device_functions_view.dart index 23a874b..ec22d2e 100644 --- a/lib/features/scene/view/device_functions_view.dart +++ b/lib/features/scene/view/device_functions_view.dart @@ -202,7 +202,7 @@ class DeviceFunctionsView extends StatelessWidget operation: function.operationName, icon: device.icon ?? '', deviceName: device.name ?? '', - uniqueId: function.uniqueCustomId, + uniqueId: function.uniqueCustomId!, operationType: function.operationDialogType, )); Navigator.pop(context); @@ -253,7 +253,7 @@ class DeviceFunctionsView extends StatelessWidget operation: function.operationName, icon: device.icon ?? '', deviceName: device.name ?? '', - uniqueId: function.uniqueCustomId, + uniqueId: function.uniqueCustomId!, operationType: function.operationDialogType, isAutomation: true, )); diff --git a/lib/features/scene/view/scene_tasks_view.dart b/lib/features/scene/view/scene_tasks_view.dart index 619353f..35a7344 100644 --- a/lib/features/scene/view/scene_tasks_view.dart +++ b/lib/features/scene/view/scene_tasks_view.dart @@ -29,6 +29,9 @@ class SceneTasksView extends StatelessWidget { final isAutomation = sceneSettings.sceneType == CreateSceneEnum.deviceStatusChanges.name; + // context.read().add(SceneTypeEvent(isAutomation + // ? CreateSceneEnum.deviceStatusChanges + // : CreateSceneEnum.tabToRun)); return DefaultScaffold( title: sceneSettings.sceneName.isNotEmpty diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart index 18fdb05..0447e8a 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart @@ -31,6 +31,10 @@ class _AlertDialogSliderStepsState extends State { super.didChangeDependencies(); final createSceneBloc = context.read(); + if (widget.taskItem.comparator != null) { + selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator); + } + if (widget.isAutomation) { final automationTempTaskList = createSceneBloc.automationTempTasksList; final automationComparatorValues = @@ -52,10 +56,6 @@ class _AlertDialogSliderStepsState extends State { _normalizeValue(widget.taskItem.operationalValues[0].minValue); } - if (widget.taskItem.comparator != null) { - selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator); - } - setState(() {}); context.read().add( @@ -69,7 +69,7 @@ class _AlertDialogSliderStepsState extends State { } double _normalizeValue(dynamic value) { - if (((widget.taskItem.code == "temp_set" && value > 200) || + if (((widget.taskItem.code == "temp_set" && value > 199) || widget.taskItem.code == "temp_current")) { return (value) / 10; } diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart index 783d8c1..7a5429b 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart @@ -49,13 +49,18 @@ class _AlertDialogTemperatureBodyState temperature = _normalizeTemperature(widget.functionValue); }); } + + // context.read().add(SelectedValueEvent( + // value: temperature * 10, + // code: widget.taskItem.code, + // )); } int _normalizeTemperature(dynamic value) { - if (value is int && value >= 100) { + if (value >= 100) { return value ~/ 10; } - return value as int? ?? 24; + return value ?? 24; } @override diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 163638b..3d0af10 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -129,7 +129,7 @@ class CustomBottomSheetWidget extends StatelessWidget { operation: functions[0].operationName, icon: Assets.delay, deviceName: 'Delay The Action', - uniqueId: functions[0].uniqueCustomId, + uniqueId: functions[0].uniqueCustomId!, operationType: functions[0].operationDialogType, )); context.read().add(const AddTaskEvent()); diff --git a/lib/features/scene/widgets/create_scene_save_button.dart b/lib/features/scene/widgets/create_scene_save_button.dart index 1bb7f8c..4762565 100644 --- a/lib/features/scene/widgets/create_scene_save_button.dart +++ b/lib/features/scene/widgets/create_scene_save_button.dart @@ -48,14 +48,10 @@ class _CreateSceneSaveButtonState extends State if (state is CreateSceneWithTasks) { if (state.success == true) { navigateToRoute(context, Routes.homeRoute); - context.showCustomSnackbar( - message: 'Scene created successfully', - icon: const Icon( - Icons.check, - color: Colors.green, - ), - ); sceneNameController.text = ''; + CustomSnackBar.greenSnackBar('Scene created successfully'); + + return; } } else if (state is CreateSceneError) { CustomSnackBar.displaySnackBar(state.message); diff --git a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart index 131f810..a291886 100644 --- a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart +++ b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart @@ -19,6 +19,8 @@ import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; +import '../../../../navigation/navigation_service.dart'; + class ThenAddedTasksContainer extends StatelessWidget with SceneOperationsDataHelper, SceneLogicHelper { ThenAddedTasksContainer({ @@ -121,7 +123,7 @@ class ThenAddedTasksContainer extends StatelessWidget createSceneBloc.add( UpdateTaskEvent( newValue: automationSelectedValue, - taskId: taskItem.uniqueCustomId, + taskId: taskItem.uniqueCustomId!, isAutomation: true, ), ); @@ -136,7 +138,7 @@ class ThenAddedTasksContainer extends StatelessWidget createSceneBloc.add( UpdateTaskEvent( newValue: selectedValue, - taskId: taskItem.uniqueCustomId, + taskId: taskItem.uniqueCustomId!, ), ); } catch (e) { @@ -144,7 +146,10 @@ class ThenAddedTasksContainer extends StatelessWidget } } - Navigator.pop(context); + WidgetsBinding.instance.addPostFrameCallback((_) { + Navigator.pop( + NavigationService.navigatorKey.currentContext!); + }); }, ); } @@ -172,7 +177,7 @@ class ThenAddedTasksContainer extends StatelessWidget ), direction: DismissDirection.endToStart, onDismissed: (direction) { - String removeFunctionById = taskItem.uniqueCustomId; + String removeFunctionById = taskItem.uniqueCustomId!; if (isAutomation == true) { context.read().add(RemoveTaskByIdEvent( diff --git a/lib/features/scene/widgets/if_then_containers/then_container.dart b/lib/features/scene/widgets/if_then_containers/then_container.dart index 1610e50..193ef78 100644 --- a/lib/features/scene/widgets/if_then_containers/then_container.dart +++ b/lib/features/scene/widgets/if_then_containers/then_container.dart @@ -47,7 +47,7 @@ class ThenDefaultContainer extends StatelessWidget { return GestureDetector( onTap: isClickable ? () => context.customBottomSheet( - child: CustomBottomSheetWidget(sceneId:sceneId), + child: CustomBottomSheetWidget(sceneId: sceneId), ) : null, child: SvgPicture.asset( @@ -99,7 +99,9 @@ class ThenDefaultContainer extends StatelessWidget { builder: (context) => const CreateSceneView())); } else { context.customBottomSheet( - child: CustomBottomSheetWidget(sceneId: sceneId,), + child: CustomBottomSheetWidget( + sceneId: sceneId, + ), ); } }, diff --git a/lib/features/scene/widgets/scene_view_widget/scene_item.dart b/lib/features/scene/widgets/scene_view_widget/scene_item.dart index b82d637..6a576da 100644 --- a/lib/features/scene/widgets/scene_view_widget/scene_item.dart +++ b/lib/features/scene/widgets/scene_view_widget/scene_item.dart @@ -35,6 +35,19 @@ class SceneItem extends StatelessWidget { Widget build(BuildContext context) { return DefaultContainer( onTap: () { + context.read().add(const SmartSceneClearEvent()); + if (disablePlayButton == false) { + BlocProvider.of(context).add( + FetchSceneTasksEvent(sceneId: scene.id, isAutomation: false)); + BlocProvider.of(context) + .add(const SceneTypeEvent(CreateSceneEnum.tabToRun)); + } else { + BlocProvider.of(context) + .add(FetchSceneTasksEvent(sceneId: scene.id, isAutomation: true)); + BlocProvider.of(context) + .add(const SceneTypeEvent(CreateSceneEnum.deviceStatusChanges)); + } + Navigator.pushNamed( context, Routes.sceneTasksRoute, @@ -46,18 +59,6 @@ class SceneItem extends StatelessWidget { sceneName: scene.name, ), ); - context.read().add(const SmartSceneClearEvent()); - if (disablePlayButton == false) { - BlocProvider.of(context) - .add(const SceneTypeEvent(CreateSceneEnum.tabToRun)); - BlocProvider.of(context).add( - FetchSceneTasksEvent(sceneId: scene.id, isAutomation: false)); - } else { - BlocProvider.of(context) - .add(const SceneTypeEvent(CreateSceneEnum.deviceStatusChanges)); - BlocProvider.of(context) - .add(FetchSceneTasksEvent(sceneId: scene.id, isAutomation: true)); - } }, child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/utils/helpers/snack_bar.dart b/lib/utils/helpers/snack_bar.dart index 61c99ee..991232c 100644 --- a/lib/utils/helpers/snack_bar.dart +++ b/lib/utils/helpers/snack_bar.dart @@ -30,7 +30,7 @@ class CustomSnackBar { Text( message, style: Theme.of(currentContext).textTheme.bodySmall!.copyWith( - fontSize: 14, fontWeight: FontWeight.w500, color: Colors.green), + fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white), ) ]), ); From 28b92ec55f22aa0418d142f6beda73e62a87c1c1 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 17:56:47 +0300 Subject: [PATCH 05/10] push alarm lock value --- .../scene/helper/functions_per_device/door_lock_functions.dart | 2 +- lib/features/scene/helper/scene_operations_data_helper.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/scene/helper/functions_per_device/door_lock_functions.dart b/lib/features/scene/helper/functions_per_device/door_lock_functions.dart index 81f3589..489c554 100644 --- a/lib/features/scene/helper/functions_per_device/door_lock_functions.dart +++ b/lib/features/scene/helper/functions_per_device/door_lock_functions.dart @@ -98,7 +98,7 @@ class DoorLockHelperFunctions { SceneOperationalValue( icon: Assets.assetsFingerprintUnlock, description: "Fingerprint Mismatch", - value: 0, + value: 'wrong_password', ), ], ), diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index 0e7fb33..b08f15b 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -987,7 +987,7 @@ mixin SceneOperationsDataHelper { SceneOperationalValue( icon: Assets.assetsFingerprintUnlock, description: "Fingerprint Mismatch", - value: 0, + value: 'wrong_password', ), ]; } From a65c602725e051aaf4eee2235dfe348382ec8386 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 18:15:01 +0300 Subject: [PATCH 06/10] push low connection --- .../scene_devices/scene_devices_body.dart | 2 +- lib/services/api/home_management_api.dart | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/features/scene/widgets/scene_devices/scene_devices_body.dart b/lib/features/scene/widgets/scene_devices/scene_devices_body.dart index 60e97c8..b5296b7 100644 --- a/lib/features/scene/widgets/scene_devices/scene_devices_body.dart +++ b/lib/features/scene/widgets/scene_devices/scene_devices_body.dart @@ -118,7 +118,7 @@ class SceneDevicesBody extends StatelessWidget { }, ); } else if (state.error != null) { - return Center(child: Text(state.error!)); + return const Center(child: Text('Something went wrong')); } else { return const SizedBox(); } diff --git a/lib/services/api/home_management_api.dart b/lib/services/api/home_management_api.dart index b49e8d7..52777d9 100644 --- a/lib/services/api/home_management_api.dart +++ b/lib/services/api/home_management_api.dart @@ -13,22 +13,26 @@ class HomeManagementAPI { var userId = await storage.read(key: UserModel.userUuidKey) ?? ''; List list = []; - await _httpService.get( - path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId), - showServerMessage: false, - expectedResponseModel: (json) { - json.forEach((value) { - list.add(DeviceModel.fromJson(value)); + try { + await _httpService.get( + path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId), + showServerMessage: false, + expectedResponseModel: (json) { + json.forEach((value) { + list.add(DeviceModel.fromJson(value)); + }); }); - }); + } catch (e) { + rethrow; + } return list; } static Future> fetchDevicesByUnitId() async { List list = []; await _httpService.get( - path: ApiEndpoints.getDevicesByUnitId - .replaceAll("{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''), + path: ApiEndpoints.getDevicesByUnitId.replaceAll( + "{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''), showServerMessage: false, expectedResponseModel: (json) { json.forEach((value) { @@ -38,7 +42,8 @@ class HomeManagementAPI { return list; } - static Future> assignDeviceToRoom(Map body) async { + static Future> assignDeviceToRoom( + Map body) async { try { final response = await _httpService.put( path: ApiEndpoints.assignDeviceToRoom, From 305680a082fd950507c2efa85578e009c91e7349 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 18:31:49 +0300 Subject: [PATCH 07/10] push remove try catch --- lib/services/api/home_management_api.dart | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/services/api/home_management_api.dart b/lib/services/api/home_management_api.dart index 52777d9..9eb35b2 100644 --- a/lib/services/api/home_management_api.dart +++ b/lib/services/api/home_management_api.dart @@ -13,18 +13,16 @@ class HomeManagementAPI { var userId = await storage.read(key: UserModel.userUuidKey) ?? ''; List list = []; - try { - await _httpService.get( - path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId), - showServerMessage: false, - expectedResponseModel: (json) { - json.forEach((value) { - list.add(DeviceModel.fromJson(value)); - }); + + await _httpService.get( + path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId), + showServerMessage: false, + expectedResponseModel: (json) { + json.forEach((value) { + list.add(DeviceModel.fromJson(value)); }); - } catch (e) { - rethrow; - } + }); + return list; } From a5a2446942b6b3b4fae6b02100fc362c54aa12c9 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sun, 4 Aug 2024 19:36:19 +0300 Subject: [PATCH 08/10] Fixed design issues --- .../scene/helper/scene_logic_helper.dart | 20 +++++++------- .../scene/widgets/bottom_sheet_widget.dart | 15 ++++------- .../widgets/create_scene_save_button.dart | 26 ++++++++----------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 1bda43d..617041b 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -15,10 +15,13 @@ import 'package:syncrow_app/utils/context_extension.dart'; mixin SceneLogicHelper { bool isOnlyDelayOrDelayLast(List tasks) { - final lastTask = tasks.last; - return tasks.every((task) => task.code == 'delay') || - lastTask.code == 'delay' || - lastTask.deviceId == 'delay'; + final lastTask = tasks.isNotEmpty ? tasks.last : null; + + return tasks.isNotEmpty + ? tasks.every((task) => task.code == 'delay') || + lastTask!.code == 'delay' || + lastTask.deviceId == 'delay' + : false; } void handleSaveButtonPress( @@ -177,24 +180,21 @@ mixin SceneLogicHelper { } } - Widget getTheCorrectDialogBody( - SceneStaticFunction taskItem, dynamic functionValue, + Widget getTheCorrectDialogBody(SceneStaticFunction taskItem, dynamic functionValue, {required bool isAutomation}) { if (taskItem.operationDialogType == OperationDialogType.temperature) { return AlertDialogTemperatureBody( taskItem: taskItem, functionValue: functionValue ?? taskItem.functionValue, ); - } else if ((taskItem.operationDialogType == - OperationDialogType.countdown) || + } else if ((taskItem.operationDialogType == OperationDialogType.countdown) || (taskItem.operationDialogType == OperationDialogType.delay)) { return AlertDialogCountdown( durationValue: taskItem.functionValue ?? 0, functionValue: functionValue ?? taskItem.functionValue, function: taskItem, ); - } else if (taskItem.operationDialogType == - OperationDialogType.integerSteps) { + } else if (taskItem.operationDialogType == OperationDialogType.integerSteps) { return AlertDialogSliderSteps( taskItem: taskItem, functionValue: functionValue ?? taskItem.functionValue, diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 3d0af10..7722498 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -60,7 +60,7 @@ class CustomBottomSheetWidget extends StatelessWidget { ), SceneListTile( assetPath: Assets.player, - titleString: 'Select Automation', + titleString: 'Select Smart Scene', minLeadingWidth: 30, assetHeight: 24, padding: const EdgeInsets.symmetric(horizontal: 20), @@ -70,8 +70,7 @@ class CustomBottomSheetWidget extends StatelessWidget { color: ColorsManager.greyColor, ), onPressed: () { - Navigator.pushNamed(context, Routes.smartAutomationSelectRoute, - arguments: sceneId); + Navigator.pushNamed(context, Routes.smartAutomationSelectRoute, arguments: sceneId); }, ), SceneListTile( @@ -93,8 +92,7 @@ class CustomBottomSheetWidget extends StatelessWidget { } void _onDelayActionPressed(BuildContext context) { - final functionValues = - context.read().selectedValues['delay']; + final functionValues = context.read().selectedValues['delay']; final functions = [ SceneStaticFunction( deviceId: 'delay', @@ -117,8 +115,7 @@ class CustomBottomSheetWidget extends StatelessWidget { ), title: functions[0].operationName, onConfirm: () { - final selectedValue = - context.read().selectedValues['delay']; + final selectedValue = context.read().selectedValues['delay']; context.read().add(TempHoldSceneTasksEvent( deviceControlModel: DeviceControlModel( deviceId: '', @@ -141,9 +138,7 @@ class CustomBottomSheetWidget extends StatelessWidget { for (var element in tempTaskList) { if (element.code == functions[0].code) { - context - .read() - .add(RemoveTempTaskByIdEvent(code: functions[0].code)); + context.read().add(RemoveTempTaskByIdEvent(code: functions[0].code)); context .read() .add(RemoveFromSelectedValueById(code: functions[0].code)); diff --git a/lib/features/scene/widgets/create_scene_save_button.dart b/lib/features/scene/widgets/create_scene_save_button.dart index 4762565..d601dc5 100644 --- a/lib/features/scene/widgets/create_scene_save_button.dart +++ b/lib/features/scene/widgets/create_scene_save_button.dart @@ -24,14 +24,13 @@ class CreateSceneSaveButton extends StatefulWidget { State createState() => _CreateSceneSaveButtonState(); } -class _CreateSceneSaveButtonState extends State - with SceneLogicHelper { +class _CreateSceneSaveButtonState extends State with SceneLogicHelper { late TextEditingController sceneNameController; @override void initState() { - sceneNameController = TextEditingController( - text: widget.sceneName.isNotEmpty ? widget.sceneName : ''); + sceneNameController = + TextEditingController(text: widget.sceneName.isNotEmpty ? widget.sceneName : ''); super.initState(); } @@ -46,12 +45,12 @@ class _CreateSceneSaveButtonState extends State return BlocConsumer( listener: (context, state) { if (state is CreateSceneWithTasks) { - if (state.success == true) { + if (state.success) { navigateToRoute(context, Routes.homeRoute); sceneNameController.text = ''; - CustomSnackBar.greenSnackBar('Scene created successfully'); - - return; + CustomSnackBar.greenSnackBar(widget.sceneName.isNotEmpty + ? 'Scene updated successfully' + : 'Scene created successfully'); } } else if (state is CreateSceneError) { CustomSnackBar.displaySnackBar(state.message); @@ -61,8 +60,7 @@ class _CreateSceneSaveButtonState extends State return DefaultButton( onPressed: () { final sceneBloc = context.read(); - final isAutomation = - sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges; + final isAutomation = sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges; if (widget.sceneName.isNotEmpty) { handleSaveButtonPress( @@ -85,13 +83,11 @@ class _CreateSceneSaveButtonState extends State elevation: WidgetStateProperty.all(0), textStyle: WidgetStateProperty.all(context.bodyMedium), hintStyle: WidgetStateProperty.all( - context.bodyMedium.copyWith( - fontSize: 14, - color: ColorsManager.secondaryTextColor), + context.bodyMedium + .copyWith(fontSize: 14, color: ColorsManager.secondaryTextColor), ), hintText: 'Enter scene name', - backgroundColor: WidgetStateProperty.all( - ColorsManager.backgroundColor), + backgroundColor: WidgetStateProperty.all(ColorsManager.backgroundColor), ), ), ), From 1297d4ec89880400507a67ab193175d7b7667eff Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 20:38:21 +0300 Subject: [PATCH 09/10] push snackbar fix and device to scene route --- .../devices/view/widgets/scene_listview.dart | 6 ++++-- .../bloc/create_scene/create_scene_bloc.dart | 4 ++++ .../widgets/create_scene_save_button.dart | 21 ++++++++++--------- .../widgets/scene_view_widget/scene_item.dart | 4 ++++ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/features/devices/view/widgets/scene_listview.dart b/lib/features/devices/view/widgets/scene_listview.dart index e0065cc..63b770f 100644 --- a/lib/features/devices/view/widgets/scene_listview.dart +++ b/lib/features/devices/view/widgets/scene_listview.dart @@ -44,11 +44,13 @@ class SceneListview extends StatelessWidget { .read() .add(const SmartSceneClearEvent()); - BlocProvider.of(context) - .add(const SceneTypeEvent(CreateSceneEnum.tabToRun)); BlocProvider.of(context).add( FetchSceneTasksEvent( sceneId: scene.id, isAutomation: false)); + + /// the state to set the scene type must be after the fetch + BlocProvider.of(context) + .add(const SceneTypeEvent(CreateSceneEnum.tabToRun)); }, child: SizedBox( width: MediaQuery.of(context).size.width * 0.4, 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 104396f..66bcf88 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -13,6 +13,7 @@ import 'package:syncrow_app/features/scene/model/create_scene_model.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; import 'package:syncrow_app/navigation/navigation_service.dart'; import 'package:syncrow_app/services/api/scene_api.dart'; +import 'package:syncrow_app/utils/helpers/snack_bar.dart'; part 'create_scene_event.dart'; part 'create_scene_state.dart'; @@ -364,6 +365,9 @@ class CreateSceneBloc extends Bloc sceneType = CreateSceneEnum.none; conditionRule = 'or'; emit(const CreateSceneWithTasks(success: true)); + CustomSnackBar.greenSnackBar(event.createSceneModel != null + ? 'Scene updated successfully' + : 'Scene created successfully'); } else { emit(const CreateSceneError(message: 'Something went wrong')); } diff --git a/lib/features/scene/widgets/create_scene_save_button.dart b/lib/features/scene/widgets/create_scene_save_button.dart index d601dc5..e1275fe 100644 --- a/lib/features/scene/widgets/create_scene_save_button.dart +++ b/lib/features/scene/widgets/create_scene_save_button.dart @@ -24,13 +24,14 @@ class CreateSceneSaveButton extends StatefulWidget { State createState() => _CreateSceneSaveButtonState(); } -class _CreateSceneSaveButtonState extends State with SceneLogicHelper { +class _CreateSceneSaveButtonState extends State + with SceneLogicHelper { late TextEditingController sceneNameController; @override void initState() { - sceneNameController = - TextEditingController(text: widget.sceneName.isNotEmpty ? widget.sceneName : ''); + sceneNameController = TextEditingController( + text: widget.sceneName.isNotEmpty ? widget.sceneName : ''); super.initState(); } @@ -48,9 +49,6 @@ class _CreateSceneSaveButtonState extends State with Scen if (state.success) { navigateToRoute(context, Routes.homeRoute); sceneNameController.text = ''; - CustomSnackBar.greenSnackBar(widget.sceneName.isNotEmpty - ? 'Scene updated successfully' - : 'Scene created successfully'); } } else if (state is CreateSceneError) { CustomSnackBar.displaySnackBar(state.message); @@ -60,7 +58,8 @@ class _CreateSceneSaveButtonState extends State with Scen return DefaultButton( onPressed: () { final sceneBloc = context.read(); - final isAutomation = sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges; + final isAutomation = + sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges; if (widget.sceneName.isNotEmpty) { handleSaveButtonPress( @@ -83,11 +82,13 @@ class _CreateSceneSaveButtonState extends State with Scen elevation: WidgetStateProperty.all(0), textStyle: WidgetStateProperty.all(context.bodyMedium), hintStyle: WidgetStateProperty.all( - context.bodyMedium - .copyWith(fontSize: 14, color: ColorsManager.secondaryTextColor), + context.bodyMedium.copyWith( + fontSize: 14, + color: ColorsManager.secondaryTextColor), ), hintText: 'Enter scene name', - backgroundColor: WidgetStateProperty.all(ColorsManager.backgroundColor), + backgroundColor: WidgetStateProperty.all( + ColorsManager.backgroundColor), ), ), ), diff --git a/lib/features/scene/widgets/scene_view_widget/scene_item.dart b/lib/features/scene/widgets/scene_view_widget/scene_item.dart index 6a576da..53c1c1d 100644 --- a/lib/features/scene/widgets/scene_view_widget/scene_item.dart +++ b/lib/features/scene/widgets/scene_view_widget/scene_item.dart @@ -39,11 +39,15 @@ class SceneItem extends StatelessWidget { if (disablePlayButton == false) { BlocProvider.of(context).add( FetchSceneTasksEvent(sceneId: scene.id, isAutomation: false)); + + /// the state to set the scene type must be after the fetch BlocProvider.of(context) .add(const SceneTypeEvent(CreateSceneEnum.tabToRun)); } else { BlocProvider.of(context) .add(FetchSceneTasksEvent(sceneId: scene.id, isAutomation: true)); + + /// the state to set the scene type must be after the fetch BlocProvider.of(context) .add(const SceneTypeEvent(CreateSceneEnum.deviceStatusChanges)); } From fe10d7a910894547451816f225d66211a2c90676 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sun, 4 Aug 2024 23:23:27 +0300 Subject: [PATCH 10/10] Bug fixes --- lib/features/app_layout/bloc/home_cubit.dart | 123 +++---- .../view/widgets/manage_home/room_screen.dart | 8 +- .../view/widgets/profile/profile_tab.dart | 2 +- .../bloc/create_scene/create_scene_bloc.dart | 87 ++--- .../door_lock_functions.dart | 8 +- .../scene/helper/scene_logic_helper.dart | 21 -- .../helper/scene_operations_data_helper.dart | 303 +++++++----------- .../widgets/create_scene_save_button.dart | 35 +- 8 files changed, 231 insertions(+), 356 deletions(-) diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart index bb1863c..5d87f26 100644 --- a/lib/features/app_layout/bloc/home_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -63,8 +63,7 @@ class HomeCubit extends Cubit { Future fetchUserInfo() async { try { - var uuid = - await const FlutterSecureStorage().read(key: UserModel.userUuidKey); + var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey); user = await ProfileApi().fetchUserInfo(uuid); emit(HomeUserInfoLoaded(user!)); // Emit state after fetching user info } catch (e) { @@ -85,12 +84,9 @@ class HomeCubit extends Cubit { selectedSpace = null; selectedRoom = null; pageIndex = 0; - OneSignal.User.pushSubscription - .removeObserver((stateChanges) => oneSignalSubscriptionObserver); - OneSignal.Notifications.removePermissionObserver( - (permission) => oneSignalPermissionObserver); - OneSignal.Notifications.removeClickListener( - (event) => oneSignalClickListenerObserver); + OneSignal.User.pushSubscription.removeObserver((stateChanges) => oneSignalSubscriptionObserver); + OneSignal.Notifications.removePermissionObserver((permission) => oneSignalPermissionObserver); + OneSignal.Notifications.removeClickListener((event) => oneSignalClickListenerObserver); return super.close(); } @@ -132,9 +128,7 @@ class HomeCubit extends Cubit { return; } - var userUuid = - await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? - ''; + var userUuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? ''; if (userUuid.isNotEmpty) { await OneSignal.login(userUuid); } @@ -142,24 +136,21 @@ class HomeCubit extends Cubit { await OneSignal.User.pushSubscription.optIn(); //this function will be called once a user is subscribed - oneSignalSubscriptionObserver = - OneSignal.User.pushSubscription.addObserver((state) async { + oneSignalSubscriptionObserver = OneSignal.User.pushSubscription.addObserver((state) async { if (state.current.optedIn) { await _sendSubscriptionId(); } }); // Send the player id when a user allows notifications - oneSignalPermissionObserver = - OneSignal.Notifications.addPermissionObserver((state) async { + oneSignalPermissionObserver = OneSignal.Notifications.addPermissionObserver((state) async { await _sendSubscriptionId(); }); //check if the player id is sent, if not send it again await _sendSubscriptionId(); - oneSignalClickListenerObserver = - OneSignal.Notifications.addClickListener((event) async { + oneSignalClickListenerObserver = OneSignal.Notifications.addClickListener((event) async { //Once the user clicks on the notification }); } catch (err) { @@ -246,9 +237,7 @@ class HomeCubit extends Cubit { Future joinAUnit(String code) async { try { - var uuid = - await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? - ''; + var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? ''; Map body = {'userUuid': uuid, 'inviteCode': code}; final success = await SpacesAPI.joinUnit(body); @@ -360,50 +349,47 @@ class HomeCubit extends Cubit { // ), // onPressed: () {}, // ), - IconButton( - icon: const Icon( - Icons.add, - size: 32, - ), - style: ButtonStyle( - foregroundColor: - WidgetStateProperty.all(ColorsManager.textPrimaryColor), - ), - onPressed: () { - Navigator.pushNamed( - NavigationService.navigatorKey.currentContext!, - Routes.sceneTasksRoute, - arguments: SceneSettingsRouteArguments( - sceneType: '', - sceneId: '', - sceneName: '', - ), - ); - NavigationService.navigatorKey.currentContext! - .read() - .add(const ClearTaskListEvent()); - NavigationService.navigatorKey.currentContext! - .read() - .add(const SceneTypeEvent(CreateSceneEnum.none)); - NavigationService.navigatorKey.currentContext! - .read() - .add(const SmartSceneClearEvent()); - BlocProvider.of( - NavigationService.navigatorKey.currentState!.context) - .add(ResetEffectivePeriod()); - }, - ), - IconButton( - icon: const Icon( - Icons.more_vert, - size: 28, - ), - style: ButtonStyle( - foregroundColor: - WidgetStateProperty.all(ColorsManager.textPrimaryColor), - ), - onPressed: () {}, - ), + // IconButton( + // icon: const Icon( + // Icons.add, + // size: 32, + // ), + // style: ButtonStyle( + // foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor), + // ), + // onPressed: () { + // Navigator.pushNamed( + // NavigationService.navigatorKey.currentContext!, + // Routes.sceneTasksRoute, + // arguments: SceneSettingsRouteArguments( + // sceneType: '', + // sceneId: '', + // sceneName: '', + // ), + // ); + // NavigationService.navigatorKey.currentContext! + // .read() + // .add(const ClearTaskListEvent()); + // NavigationService.navigatorKey.currentContext! + // .read() + // .add(const SceneTypeEvent(CreateSceneEnum.none)); + // NavigationService.navigatorKey.currentContext! + // .read() + // .add(const SmartSceneClearEvent()); + // BlocProvider.of(NavigationService.navigatorKey.currentState!.context) + // .add(ResetEffectivePeriod()); + // }, + // ), + // IconButton( + // icon: const Icon( + // Icons.more_vert, + // size: 28, + // ), + // style: ButtonStyle( + // foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor), + // ), + // onPressed: () {}, + // ), ], 'Menu': [ IconButton( @@ -433,8 +419,7 @@ class HomeCubit extends Cubit { }; static var bottomNavItems = [ - defaultBottomNavBarItem( - icon: Assets.assetsIconsDashboard, label: 'Dashboard'), + defaultBottomNavBarItem(icon: Assets.assetsIconsDashboard, label: 'Dashboard'), // defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'), defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'), defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'), @@ -460,8 +445,7 @@ class HomeCubit extends Cubit { void updateDevice(String deviceId) async { try { - final response = await DevicesAPI.firmwareDevice( - deviceId: deviceId, firmwareVersion: '0'); + final response = await DevicesAPI.firmwareDevice(deviceId: deviceId, firmwareVersion: '0'); if (response['success'] ?? false) { CustomSnackBar.displaySnackBar('No updates available'); } @@ -469,8 +453,7 @@ class HomeCubit extends Cubit { } } -BottomNavigationBarItem defaultBottomNavBarItem( - {required String icon, required String label}) { +BottomNavigationBarItem defaultBottomNavBarItem({required String icon, required String label}) { return BottomNavigationBarItem( icon: SvgPicture.asset(icon), activeIcon: SvgPicture.asset( diff --git a/lib/features/menu/view/widgets/manage_home/room_screen.dart b/lib/features/menu/view/widgets/manage_home/room_screen.dart index 3f4f0a8..34f2326 100644 --- a/lib/features/menu/view/widgets/manage_home/room_screen.dart +++ b/lib/features/menu/view/widgets/manage_home/room_screen.dart @@ -26,12 +26,14 @@ class RoomsView extends StatelessWidget { title: 'Space Management', child: state is LoadingState ? const Center(child: RefreshProgressIndicator()) - : Container( - margin: const EdgeInsets.only(top: 32), + : SizedBox( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, - child: Column( + child: ListView( children: [ + const SizedBox( + height: 32, + ), if (state is FetchRoomsState) Container( decoration: const ShapeDecoration( diff --git a/lib/features/menu/view/widgets/profile/profile_tab.dart b/lib/features/menu/view/widgets/profile/profile_tab.dart index eaa11b3..2350040 100644 --- a/lib/features/menu/view/widgets/profile/profile_tab.dart +++ b/lib/features/menu/view/widgets/profile/profile_tab.dart @@ -55,7 +55,7 @@ class ProfileTab extends StatelessWidget { fontWeight: FontWeight.bold, ), BodyMedium( - text: HomeCubit.user!.lastName ?? '', + text: HomeCubit.user?.lastName ?? '', fontWeight: FontWeight.bold, ), ], 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 66bcf88..0a52b02 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -53,8 +53,7 @@ class CreateSceneBloc extends Bloc String conditionRule = 'or'; EffectiveTime? effectiveTime; - FutureOr _onAddSceneTask( - AddTaskEvent event, Emitter emit) { + FutureOr _onAddSceneTask(AddTaskEvent event, Emitter emit) { emit(CreateSceneLoading()); if (event.isAutomation == true) { final copyList = List.from(automationTempTasksList); @@ -89,8 +88,7 @@ class CreateSceneBloc extends Bloc } } - void addToTempTaskList( - TempHoldSceneTasksEvent event, Emitter emit) { + void addToTempTaskList(TempHoldSceneTasksEvent event, Emitter emit) { emit(CreateSceneLoading()); bool updated = false; @@ -175,8 +173,7 @@ class CreateSceneBloc extends Bloc )); } - void addToTempAutomationTaskList( - TempHoldSceneTasksEvent event, Emitter emit) { + void addToTempAutomationTaskList(TempHoldSceneTasksEvent event, Emitter emit) { emit(CreateSceneLoading()); bool updated = false; for (var element in automationTempTasksList) { @@ -198,10 +195,8 @@ class CreateSceneBloc extends Bloc ], comparator: automationComparatorValues[element.code], ); - automationTempTasksList[automationTempTasksList.indexOf(element)] = - updatedElement; - automationSelectedValues[updatedElement.code] = - event.deviceControlModel.value; + automationTempTasksList[automationTempTasksList.indexOf(element)] = updatedElement; + automationSelectedValues[updatedElement.code] = event.deviceControlModel.value; updated = true; break; } @@ -221,12 +216,10 @@ class CreateSceneBloc extends Bloc icon: '', ), ], - comparator: - automationComparatorValues[event.deviceControlModel.code] ?? '==', + comparator: automationComparatorValues[event.deviceControlModel.code] ?? '==', ); automationTempTasksList.add(newElement); - automationSelectedValues[newElement.code] = - event.deviceControlModel.value; + automationSelectedValues[newElement.code] = event.deviceControlModel.value; } emit(AddSceneTask( tasksList: tasksList, @@ -235,8 +228,7 @@ class CreateSceneBloc extends Bloc )); } - FutureOr _selectedValue( - SelectedValueEvent event, Emitter emit) { + FutureOr _selectedValue(SelectedValueEvent event, Emitter emit) { if (event.isAutomation == true) { automationSelectedValues[event.code] = event.value; automationComparatorValues[event.code] = event.comparator ?? '=='; @@ -273,8 +265,7 @@ class CreateSceneBloc extends Bloc )); } - FutureOr _removeTaskById( - RemoveTaskByIdEvent event, Emitter emit) { + FutureOr _removeTaskById(RemoveTaskByIdEvent event, Emitter emit) { emit(CreateSceneLoading()); if (event.isAutomation == true) { for (var element in automationTasksList) { @@ -347,8 +338,7 @@ class CreateSceneBloc extends Bloc : await SceneApi.createScene(event.createSceneModel!); } else if (event.createAutomationModel != null) { response = event.updateScene - ? await SceneApi.updateAutomation( - event.createAutomationModel!, event.sceneId) + ? await SceneApi.updateAutomation(event.createAutomationModel!, event.sceneId) : await SceneApi.createAutomation(event.createAutomationModel!); } @@ -360,14 +350,12 @@ class CreateSceneBloc extends Bloc automationTempTasksList.clear(); automationSelectedValues.clear(); automationComparatorValues.clear(); - effectiveTime = - EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'); + effectiveTime = EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'); sceneType = CreateSceneEnum.none; conditionRule = 'or'; emit(const CreateSceneWithTasks(success: true)); - CustomSnackBar.greenSnackBar(event.createSceneModel != null - ? 'Scene updated successfully' - : 'Scene created successfully'); + CustomSnackBar.greenSnackBar( + event.updateScene ? 'Scene updated successfully' : 'Scene created successfully'); } else { emit(const CreateSceneError(message: 'Something went wrong')); } @@ -381,8 +369,7 @@ class CreateSceneBloc extends Bloc } } - FutureOr _clearTaskList( - ClearTaskListEvent event, Emitter emit) { + FutureOr _clearTaskList(ClearTaskListEvent event, Emitter emit) { emit(CreateSceneLoading()); automationTasksList.clear(); tasksList.clear(); @@ -405,8 +392,7 @@ class CreateSceneBloc extends Bloc automationTempTasksList.clear(); automationSelectedValues.clear(); automationComparatorValues.clear(); - effectiveTime = - EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'); + effectiveTime = EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'); sceneType = CreateSceneEnum.none; conditionRule = 'or'; @@ -415,14 +401,10 @@ class CreateSceneBloc extends Bloc : await SceneApi.getSceneDetails(event.sceneId); if (response.id.isNotEmpty) { if (event.isAutomation) { - automationTasksList = List.from( - getTaskListFunctionsFromApi( - actions: [], - isAutomation: true, - conditions: response.conditions)); + automationTasksList = List.from(getTaskListFunctionsFromApi( + actions: [], isAutomation: true, conditions: response.conditions)); tasksList = List.from( - getTaskListFunctionsFromApi( - actions: response.actions, isAutomation: false)); + getTaskListFunctionsFromApi(actions: response.actions, isAutomation: false)); conditionRule = response.decisionExpr ?? conditionRule; @@ -435,13 +417,11 @@ class CreateSceneBloc extends Bloc : EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'); // Set the days directly from the API response - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) + BlocProvider.of(NavigationService.navigatorKey.currentContext!) .add(SetDays(response.effectiveTime?.loops ?? '1111111')); // Set Custom Time and reset days first - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) + BlocProvider.of(NavigationService.navigatorKey.currentContext!) .add(SetCustomTime(effectiveTime!.start, effectiveTime!.end)); emit(AddSceneTask( @@ -451,8 +431,7 @@ class CreateSceneBloc extends Bloc )); } else { tasksList = List.from( - getTaskListFunctionsFromApi( - actions: response.actions, isAutomation: false)); + getTaskListFunctionsFromApi(actions: response.actions, isAutomation: false)); emit(AddSceneTask( tasksList: tasksList, condition: conditionRule, @@ -471,8 +450,7 @@ class CreateSceneBloc extends Bloc return days[index]; } - FutureOr _clearTempTaskList( - ClearTempTaskListEvent event, Emitter emit) { + FutureOr _clearTempTaskList(ClearTempTaskListEvent event, Emitter emit) { emit(CreateSceneLoading()); if (event.isAutomation == true) { automationTempTasksList.clear(); @@ -516,17 +494,13 @@ class CreateSceneBloc extends Bloc } } - FutureOr _deleteScene( - DeleteSceneEvent event, Emitter emit) async { + FutureOr _deleteScene(DeleteSceneEvent event, Emitter emit) async { emit(DeleteSceneLoading()); try { - final response = - sceneType.name == CreateSceneEnum.deviceStatusChanges.name - ? await SceneApi.deleteAutomation( - automationId: event.sceneId, unitUuid: event.unitUuid) - : await SceneApi.deleteScene( - sceneId: event.sceneId, unitUuid: event.unitUuid); + final response = sceneType.name == CreateSceneEnum.deviceStatusChanges.name + ? await SceneApi.deleteAutomation(automationId: event.sceneId, unitUuid: event.unitUuid) + : await SceneApi.deleteScene(sceneId: event.sceneId, unitUuid: event.unitUuid); if (response == true) { emit(const DeleteSceneSuccess(true)); } else { @@ -537,8 +511,7 @@ class CreateSceneBloc extends Bloc } } - FutureOr _updateTaskValue( - UpdateTaskEvent event, Emitter emit) { + FutureOr _updateTaskValue(UpdateTaskEvent event, Emitter emit) { emit(CreateSceneLoading()); if (event.isAutomation == true) { for (var i = 0; i < automationTasksList.length; i++) { @@ -574,8 +547,7 @@ class CreateSceneBloc extends Bloc )); } - FutureOr _selectConditionRule( - SelectConditionEvent event, Emitter emit) { + FutureOr _selectConditionRule(SelectConditionEvent event, Emitter emit) { emit(CreateSceneInitial()); if (event.condition.contains('any')) { conditionRule = 'or'; @@ -590,8 +562,7 @@ class CreateSceneBloc extends Bloc )); } - FutureOr _sceneTypeEvent( - SceneTypeEvent event, Emitter emit) { + FutureOr _sceneTypeEvent(SceneTypeEvent event, Emitter emit) { // emit(CreateSceneInitial()); if (event.type == CreateSceneEnum.tabToRun) { diff --git a/lib/features/scene/helper/functions_per_device/door_lock_functions.dart b/lib/features/scene/helper/functions_per_device/door_lock_functions.dart index 489c554..501acb1 100644 --- a/lib/features/scene/helper/functions_per_device/door_lock_functions.dart +++ b/lib/features/scene/helper/functions_per_device/door_lock_functions.dart @@ -16,10 +16,8 @@ class DoorLockHelperFunctions { code: 'normal_open_switch', operationDialogType: OperationDialogType.onOff, operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), + SceneOperationalValue(icon: Assets.assetsAcPower, description: "ON", value: true), + SceneOperationalValue(icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), ], ), ]; @@ -98,7 +96,7 @@ class DoorLockHelperFunctions { SceneOperationalValue( icon: Assets.assetsFingerprintUnlock, description: "Fingerprint Mismatch", - value: 'wrong_password', + value: 'wrong_finger', ), ], ), diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 617041b..c2f50b6 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -45,27 +45,6 @@ mixin SceneLogicHelper { ); return; } - if (isAutomation == true && conditions.isEmpty) { - context.showCustomSnackbar( - message: 'Conditions Must not be empty!', - icon: const Icon( - Icons.error, - color: Colors.red, - ), - ); - return; - } - - if (isAutomation == true && actions.isEmpty) { - context.showCustomSnackbar( - message: 'Actions Must not be empty!', - icon: const Icon( - Icons.error, - color: Colors.red, - ), - ); - return; - } if (isAutomation) { final createAutomationModel = CreateAutomationModel( diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index b08f15b..53f760e 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -14,9 +14,8 @@ import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; mixin SceneOperationsDataHelper { - final Map, String, String, dynamic, bool)> - _functionMap = { + final Map, String, String, dynamic, bool)> _functionMap = + { DeviceType.LightBulb: lightBulbFunctions, DeviceType.CeilingSensor: ceilingSensorFunctions, DeviceType.WallSensor: wallSensorFunctions, @@ -46,22 +45,16 @@ mixin SceneOperationsDataHelper { required bool isAutomation, }) { final functionValue = null; - return _functionMap[type]?.call( - functions, deviceId, deviceName, functionValue, isAutomation) ?? - lightBulbFunctions( - functions, deviceId, deviceName, functionValue, isAutomation); + return _functionMap[type]?.call(functions, deviceId, deviceName, functionValue, isAutomation) ?? + lightBulbFunctions(functions, deviceId, deviceName, functionValue, isAutomation); } String getTitle({DeviceType? type}) { return _titleMap[type] ?? ''; } - static List ceilingSensorFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + static List ceilingSensorFunctions(List functions, + String deviceId, String deviceName, dynamic functionValue, bool isAutomation) { if (isAutomation) { return PresenceSensorHelperFunctions.automationPresenceSensorFunctions( deviceId, deviceName, functionValue); @@ -70,35 +63,22 @@ mixin SceneOperationsDataHelper { deviceId, deviceName, functionValue); } - static List curtainFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + static List curtainFunctions(List functions, String deviceId, + String deviceName, dynamic functionValue, bool isAutomation) { return []; } - static List doorLockFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + static List doorLockFunctions(List functions, String deviceId, + String deviceName, dynamic functionValue, bool isAutomation) { if (isAutomation) { return DoorLockHelperFunctions.doorLockAutomationFunctions( deviceId, deviceName, functionValue); } - return DoorLockHelperFunctions.doorLockTapToRunFunctions( - deviceId, deviceName, functionValue); + return DoorLockHelperFunctions.doorLockTapToRunFunctions(deviceId, deviceName, functionValue); } - static List wallSensorFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + static List wallSensorFunctions(List functions, + String deviceId, String deviceName, dynamic functionValue, bool isAutomation) { if (isAutomation) { return HumanPresenceHelperFunctions.automationHumanPresenceFunctions( deviceId, deviceName, functionValue); @@ -107,51 +87,31 @@ mixin SceneOperationsDataHelper { deviceId, deviceName, functionValue); } - static List lightBulbFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + static List lightBulbFunctions(List functions, + String deviceId, String deviceName, dynamic functionValue, bool isAutomation) { return []; } - static List gatewayFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { - return GatewayHelperFunctions.tabToRunGatewayFunctions( - deviceId, deviceName, functionValue); + static List gatewayFunctions(List functions, String deviceId, + String deviceName, dynamic functionValue, bool isAutomation) { + return GatewayHelperFunctions.tabToRunGatewayFunctions(deviceId, deviceName, functionValue); } - static List threeGangFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + static List threeGangFunctions(List functions, + String deviceId, String deviceName, dynamic functionValue, bool isAutomation) { if (isAutomation) { return ThreeGangHelperFunctions.threeGangAutomationFunctions( deviceId, deviceName, functionValue); } - return ThreeGangHelperFunctions.threeGangHelperFunctions( - deviceId, deviceName, functionValue); + return ThreeGangHelperFunctions.threeGangHelperFunctions(deviceId, deviceName, functionValue); } - static List acFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + static List acFunctions(List functions, String deviceId, + String deviceName, dynamic functionValue, bool isAutomation) { if (isAutomation) { - return ACFunctionsHelper.automationAcFunctions( - deviceId, deviceName, functionValue); + return ACFunctionsHelper.automationAcFunctions(deviceId, deviceName, functionValue); } - return ACFunctionsHelper.tabToRunAcFunctions( - deviceId, deviceName, functionValue); + return ACFunctionsHelper.tabToRunAcFunctions(deviceId, deviceName, functionValue); } List getTaskListFunctionsFromApi({ @@ -189,12 +149,8 @@ mixin SceneOperationsDataHelper { SceneStaticFunction( deviceId: action.entityId, deviceName: action.name.toString(), - deviceIcon: action.type == 'automation' - ? Assets.player - : Assets.handClickIcon, - icon: action.type == 'automation' - ? Assets.player - : Assets.handClickIcon, + deviceIcon: action.type == 'automation' ? Assets.player : Assets.handClickIcon, + icon: action.type == 'automation' ? Assets.player : Assets.handClickIcon, operationName: action.type.toString(), operationDialogType: OperationDialogType.onOff, functionValue: action.actionExecutor, @@ -214,8 +170,7 @@ mixin SceneOperationsDataHelper { ), ); } else { - functions - .add(_mapExecutorPropertyToSceneFunction(action, isAutomation)); + functions.add(_mapExecutorPropertyToSceneFunction(action, isAutomation)); } } @@ -251,9 +206,7 @@ mixin SceneOperationsDataHelper { }) { final executorProperty = action.executorProperty; - final Map - functionMap = { + final Map functionMap = { 'sensitivity': _createSensitivityFunction, 'normal_open_switch': _createNormalOpenSwitchFunction, 'unlock_fingerprint': _createUnlockFingerprintFunction, @@ -329,16 +282,14 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createSensitivityFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createSensitivityFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Presence Sensor', Assets.assetsIconsSensors, 'Sensitivity', - isAutomation - ? OperationDialogType.integerSteps - : OperationDialogType.listOfOptions, + isAutomation ? OperationDialogType.integerSteps : OperationDialogType.listOfOptions, isAutomation ? _createIntegerStepsOptions() : _createSensitivityOptions(), isAutomation, comparator, @@ -346,8 +297,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createNormalOpenSwitchFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createNormalOpenSwitchFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -400,8 +351,8 @@ mixin SceneOperationsDataHelper { ]; } - SceneStaticFunction _createUnlockFingerprintFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createUnlockFingerprintFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -415,8 +366,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createUnlockPasswordFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createUnlockPasswordFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -430,8 +381,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createUnlockCardFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createUnlockCardFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -445,8 +396,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createAlarmLockFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createAlarmLockFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -460,8 +411,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createUnlockRequestFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createUnlockRequestFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -475,8 +426,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createResidualElectricityFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createResidualElectricityFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -490,8 +441,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createReverseLockFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createReverseLockFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -505,8 +456,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createUnlockAppFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createUnlockAppFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -520,8 +471,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createHijackFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createHijackFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -535,8 +486,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createDoorbellFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createDoorbellFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -550,8 +501,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createUnlockTemporaryFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createUnlockTemporaryFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'WIFI LOCK PRO', @@ -565,8 +516,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createFarDetectionFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createFarDetectionFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -580,8 +531,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createMotionSensitivityFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createMotionSensitivityFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -595,8 +546,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createMotionlessSensitivityFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createMotionlessSensitivityFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -610,8 +561,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createIndicatorFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createIndicatorFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -625,8 +576,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createPresenceTimeFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createPresenceTimeFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -640,8 +591,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createPresenceStateFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createPresenceStateFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -655,16 +606,14 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createDisCurrentFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createDisCurrentFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', Assets.assetsIconsSensors, 'Current Distance', - isAutomation - ? OperationDialogType.integerSteps - : OperationDialogType.countdown, + isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown, _createCurrentDistanceOptions(), isAutomation, comparator, @@ -672,8 +621,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createIlluminanceValueFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createIlluminanceValueFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -687,8 +636,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createCheckingResultFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createCheckingResultFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Human Presence Sensor', @@ -702,8 +651,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createSwitchFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createSwitchFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -717,27 +666,23 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createTempSetFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createTempSetFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', Assets.assetsIconsAC, 'Set Temperature', - isAutomation - ? OperationDialogType.integerSteps - : OperationDialogType.temperature, - isAutomation - ? _createAutomationTemperatureOptions() - : _createTemperatureOptions(), + isAutomation ? OperationDialogType.integerSteps : OperationDialogType.temperature, + isAutomation ? _createAutomationTemperatureOptions() : _createTemperatureOptions(), isAutomation, comparator, uniqueCustomId, ); } - SceneStaticFunction _createTempCurrentFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createTempCurrentFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -751,8 +696,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createModeFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createModeFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -766,8 +711,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createLevelFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createLevelFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -781,8 +726,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createChildLockFunction(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createChildLockFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Smart AC Thermostat - Grey - Model A', @@ -796,8 +741,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createSwitch1Function(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createSwitch1Function( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -811,8 +756,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createSwitch2Function(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createSwitch2Function( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -826,8 +771,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createSwitch3Function(Action action, bool isAutomation, - String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createSwitch3Function( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', @@ -841,65 +786,53 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createCountdown1Function(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createCountdown1Function( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', Assets.assetsIcons3GangSwitch, 'Light 1 CountDown', - isAutomation - ? OperationDialogType.integerSteps - : OperationDialogType.countdown, - isAutomation - ? _createAutomationCountDownOptions() - : _createCountdownOptions(), + isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown, + isAutomation ? _createAutomationCountDownOptions() : _createCountdownOptions(), isAutomation, comparator, uniqueCustomId, ); } - SceneStaticFunction _createCountdown2Function(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createCountdown2Function( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', Assets.assetsIcons3GangSwitch, 'Light 2 CountDown', - isAutomation - ? OperationDialogType.integerSteps - : OperationDialogType.countdown, - isAutomation - ? _createAutomationCountDownOptions() - : _createCountdownOptions(), + isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown, + isAutomation ? _createAutomationCountDownOptions() : _createCountdownOptions(), isAutomation, comparator, uniqueCustomId, ); } - SceneStaticFunction _createCountdown3Function(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createCountdown3Function( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, '3 Gang Button Switch L-L', Assets.assetsIcons3GangSwitch, 'Light 3 CountDown', - isAutomation - ? OperationDialogType.integerSteps - : OperationDialogType.countdown, - isAutomation - ? _createAutomationCountDownOptions() - : _createCountdownOptions(), + isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown, + isAutomation ? _createAutomationCountDownOptions() : _createCountdownOptions(), isAutomation, comparator, uniqueCustomId, ); } - SceneStaticFunction _createSwitchAlarmSoundFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createSwitchAlarmSoundFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Gateway', @@ -913,8 +846,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createMasterStateFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createMasterStateFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Gateway', @@ -928,8 +861,8 @@ mixin SceneOperationsDataHelper { ); } - SceneStaticFunction _createFactoryResetFunction(Action action, - bool isAutomation, String? comparator, String? uniqueCustomId) { + SceneStaticFunction _createFactoryResetFunction( + Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { return _createSceneFunction( action, 'Gateway', @@ -987,7 +920,7 @@ mixin SceneOperationsDataHelper { SceneOperationalValue( icon: Assets.assetsFingerprintUnlock, description: "Fingerprint Mismatch", - value: 'wrong_password', + value: 'wrong_finger', ), ]; } @@ -1247,12 +1180,8 @@ mixin SceneOperationsDataHelper { uniqueCustomId: taskItem.uniqueCustomId, deviceId: taskItem.deviceId, deviceName: taskItem.deviceName.toString(), - deviceIcon: taskItem.operationName == 'automation' - ? Assets.player - : Assets.handClickIcon, - icon: taskItem.operationName == 'automation' - ? Assets.player - : Assets.handClickIcon, + deviceIcon: taskItem.operationName == 'automation' ? Assets.player : Assets.handClickIcon, + icon: taskItem.operationName == 'automation' ? Assets.player : Assets.handClickIcon, operationName: taskItem.operationName, operationDialogType: OperationDialogType.onOff, functionValue: taskItem.functionValue == 'rule_enable' ? true : false, diff --git a/lib/features/scene/widgets/create_scene_save_button.dart b/lib/features/scene/widgets/create_scene_save_button.dart index e1275fe..985bfb3 100644 --- a/lib/features/scene/widgets/create_scene_save_button.dart +++ b/lib/features/scene/widgets/create_scene_save_button.dart @@ -24,14 +24,13 @@ class CreateSceneSaveButton extends StatefulWidget { State createState() => _CreateSceneSaveButtonState(); } -class _CreateSceneSaveButtonState extends State - with SceneLogicHelper { +class _CreateSceneSaveButtonState extends State with SceneLogicHelper { late TextEditingController sceneNameController; @override void initState() { - sceneNameController = TextEditingController( - text: widget.sceneName.isNotEmpty ? widget.sceneName : ''); + sceneNameController = + TextEditingController(text: widget.sceneName.isNotEmpty ? widget.sceneName : ''); super.initState(); } @@ -58,8 +57,24 @@ class _CreateSceneSaveButtonState extends State return DefaultButton( onPressed: () { final sceneBloc = context.read(); - final isAutomation = - sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges; + if (sceneBloc.tasksList.isEmpty && sceneBloc.automationTasksList.isEmpty) { + return; + } + final isAutomation = sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges; + + if (isAutomation && sceneBloc.automationTasksList.isEmpty) { + CustomSnackBar.displaySnackBar( + 'Conditions Must not be empty!', + ); + return; + } + + if (isAutomation && sceneBloc.tasksList.isEmpty) { + CustomSnackBar.displaySnackBar( + 'Actions Must not be empty!', + ); + return; + } if (widget.sceneName.isNotEmpty) { handleSaveButtonPress( @@ -82,13 +97,11 @@ class _CreateSceneSaveButtonState extends State elevation: WidgetStateProperty.all(0), textStyle: WidgetStateProperty.all(context.bodyMedium), hintStyle: WidgetStateProperty.all( - context.bodyMedium.copyWith( - fontSize: 14, - color: ColorsManager.secondaryTextColor), + context.bodyMedium + .copyWith(fontSize: 14, color: ColorsManager.secondaryTextColor), ), hintText: 'Enter scene name', - backgroundColor: WidgetStateProperty.all( - ColorsManager.backgroundColor), + backgroundColor: WidgetStateProperty.all(ColorsManager.backgroundColor), ), ), ),