diff --git a/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart b/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart index 33cfffee..1dd84c19 100644 --- a/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart +++ b/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart @@ -10,8 +10,9 @@ import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; class DeviceDialogHelper { static Future?> showDeviceDialog( BuildContext context, - Map data, - ) async { + Map data, { + required bool removeComparetors, + }) async { final functions = data['functions'] as List; try { @@ -20,6 +21,7 @@ class DeviceDialogHelper { data['productType'], data, functions, + removeComparetors: removeComparetors, ); if (result != null) { @@ -33,34 +35,49 @@ class DeviceDialogHelper { } static Future?> _getDialogForDeviceType( - BuildContext context, - String productType, - Map data, - List functions, - ) async { + BuildContext context, + String productType, + Map data, + List functions, + {required bool removeComparetors}) async { final routineBloc = context.read(); final deviceSelectedFunctions = routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? []; switch (productType) { case 'AC': - return ACHelper.showACFunctionsDialog(context, functions, - data['device'], deviceSelectedFunctions, data['uniqueCustomId']); + return ACHelper.showACFunctionsDialog( + context, + functions, + data['device'], + deviceSelectedFunctions, + data['uniqueCustomId'], + removeComparetors); case '1G': - return OneGangSwitchHelper.showSwitchFunctionsDialog(context, functions, - data['device'], deviceSelectedFunctions, data['uniqueCustomId']); + return OneGangSwitchHelper.showSwitchFunctionsDialog( + context, + functions, + data['device'], + deviceSelectedFunctions, + data['uniqueCustomId'], + removeComparetors); case '2G': - return TwoGangSwitchHelper.showSwitchFunctionsDialog(context, functions, - data['device'], deviceSelectedFunctions, data['uniqueCustomId']); + return TwoGangSwitchHelper.showSwitchFunctionsDialog( + context, + functions, + data['device'], + deviceSelectedFunctions, + data['uniqueCustomId'], + removeComparetors); case '3G': return ThreeGangSwitchHelper.showSwitchFunctionsDialog( - context, - functions, - data['device'], - deviceSelectedFunctions, - data['uniqueCustomId'], - ); + context, + functions, + data['device'], + deviceSelectedFunctions, + data['uniqueCustomId'], + removeComparetors); default: return null; } diff --git a/lib/pages/routiens/widgets/if_container.dart b/lib/pages/routiens/widgets/if_container.dart index da2b540b..9c357a17 100644 --- a/lib/pages/routiens/widgets/if_container.dart +++ b/lib/pages/routiens/widgets/if_container.dart @@ -26,7 +26,9 @@ class IfContainer extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), + const Text('IF', + style: TextStyle( + fontSize: 18, fontWeight: FontWeight.bold)), if (state.isAutomation && state.ifItems.isNotEmpty) AutomationOperatorSelector( selectedOperator: state.selectedAutomationOperator), @@ -53,33 +55,44 @@ class IfContainer extends StatelessWidget { (index) => GestureDetector( onTap: () async { if (!state.isTabToRun) { - final result = await DeviceDialogHelper.showDeviceDialog( - context, state.ifItems[index]); + final result = await DeviceDialogHelper + .showDeviceDialog( + context, state.ifItems[index], + removeComparetors: false); if (result != null) { - context - .read() - .add(AddToIfContainer(state.ifItems[index], false)); - } else if (!['AC', '1G', '2G', '3G'] - .contains(state.ifItems[index]['productType'])) { - context - .read() - .add(AddToIfContainer(state.ifItems[index], false)); + context.read().add( + AddToIfContainer( + state.ifItems[index], false)); + } else if (![ + 'AC', + '1G', + '2G', + '3G' + ].contains( + state.ifItems[index]['productType'])) { + context.read().add( + AddToIfContainer( + state.ifItems[index], false)); } } }, child: DraggableCard( - imagePath: state.ifItems[index]['imagePath'] ?? '', + imagePath: + state.ifItems[index]['imagePath'] ?? '', title: state.ifItems[index]['title'] ?? '', deviceData: state.ifItems[index], - padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8), + padding: const EdgeInsets.symmetric( + horizontal: 4, vertical: 8), isFromThen: false, isFromIf: true, onRemove: () { - context.read().add(RemoveDragCard( - index: index, - isFromThen: false, - key: state.ifItems[index]['uniqueCustomId'])); + context.read().add( + RemoveDragCard( + index: index, + isFromThen: false, + key: state.ifItems[index] + ['uniqueCustomId'])); }, ), )), @@ -100,14 +113,23 @@ class IfContainer extends StatelessWidget { if (!state.isTabToRun) { if (mutableData['deviceId'] == 'tab_to_run') { - context.read().add(AddToIfContainer(mutableData, true)); + context + .read() + .add(AddToIfContainer(mutableData, true)); } else { - final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData); + final result = await DeviceDialogHelper.showDeviceDialog( + context, mutableData, + removeComparetors: false); if (result != null) { - context.read().add(AddToIfContainer(mutableData, false)); - } else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) { - context.read().add(AddToIfContainer(mutableData, false)); + context + .read() + .add(AddToIfContainer(mutableData, false)); + } else if (!['AC', '1G', '2G', '3G'] + .contains(mutableData['productType'])) { + context + .read() + .add(AddToIfContainer(mutableData, false)); } } } @@ -153,7 +175,9 @@ class AutomationOperatorSelector extends StatelessWidget { ), ), onPressed: () { - context.read().add(const ChangeAutomationOperator(operator: 'or')); + context + .read() + .add(const ChangeAutomationOperator(operator: 'or')); }, ), Container( @@ -179,7 +203,9 @@ class AutomationOperatorSelector extends StatelessWidget { ), ), onPressed: () { - context.read().add(const ChangeAutomationOperator(operator: 'and')); + context + .read() + .add(const ChangeAutomationOperator(operator: 'and')); }, ), ], diff --git a/lib/pages/routiens/widgets/routine_dialogs/ac_dialog.dart b/lib/pages/routiens/widgets/routine_dialogs/ac_dialog.dart index e8b87a16..39e342ff 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/ac_dialog.dart +++ b/lib/pages/routiens/widgets/routine_dialogs/ac_dialog.dart @@ -19,6 +19,7 @@ class ACHelper { AllDevicesModel? device, List? deviceSelectedFunctions, String uniqueCustomId, + bool? removeComparetors, ) async { List acFunctions = functions.whereType().toList(); @@ -84,6 +85,7 @@ class ACHelper { acFunctions: acFunctions, device: device, operationName: selectedOperationName ?? '', + removeComparators: removeComparetors, ), ), ], @@ -179,6 +181,7 @@ class ACHelper { required List acFunctions, AllDevicesModel? device, required String operationName, + bool? removeComparators, }) { if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') { final initialValue = selectedFunctionData?.value ?? 200; @@ -190,6 +193,7 @@ class ACHelper { device: device, operationName: operationName, selectedFunctionData: selectedFunctionData, + removeComparators: removeComparators, ); } @@ -217,18 +221,20 @@ class ACHelper { AllDevicesModel? device, required String operationName, DeviceFunctionData? selectedFunctionData, + bool? removeComparators, }) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - _buildConditionToggle( - context, - currentCondition, - selectCode, - device, - operationName, - selectedFunctionData, - ), + if (removeComparators != true) + _buildConditionToggle( + context, + currentCondition, + selectCode, + device, + operationName, + selectedFunctionData, + ), const SizedBox(height: 20), _buildTemperatureDisplay( context, diff --git a/lib/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart b/lib/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart index 00f936d6..e7d7209f 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart +++ b/lib/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart @@ -20,6 +20,7 @@ class OneGangSwitchHelper { AllDevicesModel? device, List? deviceSelectedFunctions, String uniqueCustomId, + bool removeComparetors, ) async { List acFunctions = functions.whereType().toList(); @@ -106,6 +107,7 @@ class OneGangSwitchHelper { acFunctions: acFunctions, device: device, operationName: selectedOperationName ?? '', + removeComparetors: removeComparetors, ), ), ], @@ -162,6 +164,7 @@ class OneGangSwitchHelper { required List acFunctions, AllDevicesModel? device, required String operationName, + required bool removeComparetors, }) { if (selectedFunction == 'countdown_1') { final initialValue = selectedFunctionData?.value ?? 200; @@ -173,6 +176,7 @@ class OneGangSwitchHelper { device: device, operationName: operationName, selectedFunctionData: selectedFunctionData, + removeComparetors: removeComparetors, ); } @@ -199,18 +203,20 @@ class OneGangSwitchHelper { AllDevicesModel? device, required String operationName, DeviceFunctionData? selectedFunctionData, + required bool removeComparetors, }) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - _buildConditionToggle( - context, - currentCondition, - selectCode, - device, - operationName, - selectedFunctionData, - ), + if (removeComparetors != true) + _buildConditionToggle( + context, + currentCondition, + selectCode, + device, + operationName, + selectedFunctionData, + ), const SizedBox(height: 20), _buildCountDownDisplay(context, initialValue, device, operationName, selectedFunctionData, selectCode), diff --git a/lib/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart b/lib/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart index ae704ded..bb23ece4 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart +++ b/lib/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart @@ -20,6 +20,7 @@ class ThreeGangSwitchHelper { AllDevicesModel? device, List? deviceSelectedFunctions, String uniqueCustomId, + bool removeComparetors, ) async { List switchFunctions = functions.whereType().toList(); @@ -106,6 +107,7 @@ class ThreeGangSwitchHelper { switchFunctions: switchFunctions, device: device, operationName: selectedOperationName ?? '', + removeComparetors: removeComparetors, ), ), ], @@ -162,6 +164,7 @@ class ThreeGangSwitchHelper { required List switchFunctions, AllDevicesModel? device, required String operationName, + required bool removeComparetors, }) { if (selectedFunction == 'countdown_1' || selectedFunction == 'countdown_2' || @@ -175,6 +178,7 @@ class ThreeGangSwitchHelper { device: device, operationName: operationName, selectedFunctionData: selectedFunctionData, + removeComparetors: removeComparetors, ); } @@ -201,18 +205,20 @@ class ThreeGangSwitchHelper { AllDevicesModel? device, required String operationName, DeviceFunctionData? selectedFunctionData, + bool? removeComparetors, }) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - _buildConditionToggle( - context, - currentCondition, - selectCode, - device, - operationName, - selectedFunctionData, - ), + if (removeComparetors != true) + _buildConditionToggle( + context, + currentCondition, + selectCode, + device, + operationName, + selectedFunctionData, + ), const SizedBox(height: 20), _buildCountDownDisplay(context, initialValue, device, operationName, selectedFunctionData, selectCode), diff --git a/lib/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart b/lib/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart index d017103e..f2a0ebd0 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart +++ b/lib/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart @@ -20,6 +20,7 @@ class TwoGangSwitchHelper { AllDevicesModel? device, List? deviceSelectedFunctions, String uniqueCustomId, + bool removeComparetors, ) async { List switchFunctions = functions.whereType().toList(); @@ -106,6 +107,7 @@ class TwoGangSwitchHelper { switchFunctions: switchFunctions, device: device, operationName: selectedOperationName ?? '', + removeComparetors: removeComparetors, ), ), ], @@ -162,6 +164,7 @@ class TwoGangSwitchHelper { required List switchFunctions, AllDevicesModel? device, required String operationName, + required bool removeComparetors, }) { if (selectedFunction == 'countdown_1' || selectedFunction == 'countdown_2') { @@ -174,6 +177,7 @@ class TwoGangSwitchHelper { device: device, operationName: operationName, selectedFunctionData: selectedFunctionData, + removeComparetors: removeComparetors, ); } @@ -200,18 +204,20 @@ class TwoGangSwitchHelper { AllDevicesModel? device, required String operationName, DeviceFunctionData? selectedFunctionData, + bool? removeComparetors, }) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - _buildConditionToggle( - context, - currentCondition, - selectCode, - device, - operationName, - selectedFunctionData, - ), + if (removeComparetors != true) + _buildConditionToggle( + context, + currentCondition, + selectCode, + device, + operationName, + selectedFunctionData, + ), const SizedBox(height: 20), _buildCountDownDisplay(context, initialValue, device, operationName, selectedFunctionData, selectCode), diff --git a/lib/pages/routiens/widgets/then_container.dart b/lib/pages/routiens/widgets/then_container.dart index 8dbc5904..9491e8fd 100644 --- a/lib/pages/routiens/widgets/then_container.dart +++ b/lib/pages/routiens/widgets/then_container.dart @@ -26,7 +26,9 @@ class ThenContainer extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text('THEN', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), + const Text('THEN', + style: TextStyle( + fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), Wrap( spacing: 8, @@ -35,12 +37,16 @@ class ThenContainer extends StatelessWidget { state.thenItems.length, (index) => GestureDetector( onTap: () async { - if (state.thenItems[index]['deviceId'] == 'delay') { - final result = await DelayHelper.showDelayPickerDialog( - context, state.thenItems[index]); + if (state.thenItems[index]['deviceId'] == + 'delay') { + final result = await DelayHelper + .showDelayPickerDialog( + context, state.thenItems[index]); if (result != null) { - context.read().add(AddToThenContainer({ + context + .read() + .add(AddToThenContainer({ ...state.thenItems[index], 'imagePath': Assets.delay, 'title': 'Delay', @@ -49,32 +55,41 @@ class ThenContainer extends StatelessWidget { return; } - final result = await DeviceDialogHelper.showDeviceDialog( - context, state.thenItems[index]); + final result = await DeviceDialogHelper + .showDeviceDialog( + context, state.thenItems[index], + removeComparetors: true); if (result != null) { - context - .read() - .add(AddToThenContainer(state.thenItems[index])); + context.read().add( + AddToThenContainer( + state.thenItems[index])); } else if (!['AC', '1G', '2G', '3G'] - .contains(state.thenItems[index]['productType'])) { - context - .read() - .add(AddToThenContainer(state.thenItems[index])); + .contains(state.thenItems[index] + ['productType'])) { + context.read().add( + AddToThenContainer( + state.thenItems[index])); } }, child: DraggableCard( - imagePath: state.thenItems[index]['imagePath'] ?? '', - title: state.thenItems[index]['title'] ?? '', + imagePath: state.thenItems[index] + ['imagePath'] ?? + '', + title: + state.thenItems[index]['title'] ?? '', deviceData: state.thenItems[index], - padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8), + padding: const EdgeInsets.symmetric( + horizontal: 4, vertical: 8), isFromThen: true, isFromIf: false, onRemove: () { - context.read().add(RemoveDragCard( - index: index, - isFromThen: true, - key: state.thenItems[index]['uniqueCustomId'])); + context.read().add( + RemoveDragCard( + index: index, + isFromThen: true, + key: state.thenItems[index] + ['uniqueCustomId'])); }, ), ))), @@ -83,21 +98,6 @@ class ThenContainer extends StatelessWidget { ), ); }, - // onWillAcceptWithDetails: (data) { - // if (data == null) return false; - // return data.data; - - // // if (state.isTabToRun) { - // // return data.data['type'] == 'automation'; - // // } - - // // if (state.isAutomation) { - // // return data.data['type'] == 'scene' || - // // data.data['type'] == 'automation'; - // // } - - // // return data.data['deviceId'] != null; - // }, onAcceptWithDetails: (data) async { final uniqueCustomId = const Uuid().v4(); final mutableData = Map.from(data.data); @@ -131,7 +131,7 @@ class ThenContainer extends StatelessWidget { if (mutableData['type'] == 'tap_to_run' && state.isAutomation) { context.read().add(AddToThenContainer({ ...mutableData, - 'imagePath': Assets.loginLogo, + 'imagePath': Assets.logo, 'title': mutableData['name'], })); @@ -143,7 +143,8 @@ class ThenContainer extends StatelessWidget { } if (mutableData['deviceId'] == 'delay') { - final result = await DelayHelper.showDelayPickerDialog(context, mutableData); + final result = + await DelayHelper.showDelayPickerDialog(context, mutableData); if (result != null) { context.read().add(AddToThenContainer({ @@ -155,10 +156,13 @@ class ThenContainer extends StatelessWidget { return; } - final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData); + final result = await DeviceDialogHelper.showDeviceDialog( + context, mutableData, + removeComparetors: true); if (result != null) { context.read().add(AddToThenContainer(mutableData)); - } else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) { + } else if (!['AC', '1G', '2G', '3G'] + .contains(mutableData['productType'])) { context.read().add(AddToThenContainer(mutableData)); } },