From 20ded336d3222571d8116578682111ccddf6bf39 Mon Sep 17 00:00:00 2001 From: Mohammad Salameh Date: Thu, 4 Apr 2024 00:45:54 +0300 Subject: [PATCH] Refactor AC interface temp unit control logic Refactor the control logic in the AC interface temp unit widget to handle device control actions more efficiently and improve code readability. --- .../widgets/ACs/ac_interface_temp_unit.dart | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart index e29ee08..1310107 100644 --- a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart +++ b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart @@ -88,8 +88,12 @@ class AcInterfaceTempUnit extends StatelessWidget { if (valueAsString.endsWith(".0") || valueAsString.endsWith(".5")) { value = double.parse(valueAsString); - // DevicesCubit.getInstance() - // .setACTemp(DeviceModel, value); + DevicesCubit.getInstance().deviceControl( + DeviceControlModel( + deviceId: acDevice.id, + code: 'temp_set', + value: value * 10), + acDevice.id!); } }, ), @@ -104,6 +108,15 @@ class AcInterfaceTempUnit extends StatelessWidget { dimension: 24, child: InkWell( onTap: () { + //TODO refactor the loading check + if (state is GetDeviceStatusLoading && + state.code == 'temp_set' || + state is DeviceControlSuccess && + state.code == 'temp_set' || + state is DeviceControlLoading && + state.code == 'temp_set') { + return; + } if (setToTemp > 20) { DevicesCubit.getInstance().deviceControl( DeviceControlModel( @@ -124,8 +137,14 @@ class AcInterfaceTempUnit extends StatelessWidget { // text: "${DeviceModel.coolTo}° C", text: '$setToTemp° C', style: context.bodyLarge.copyWith( - color: - ColorsManager.primaryColor.withOpacity(0.6), + color: state is GetDeviceStatusLoading && + state.code == 'temp_set' || + state is DeviceControlSuccess && + state.code == 'temp_set' || + state is DeviceControlLoading && + state.code == 'temp_set' + ? Colors.grey + : ColorsManager.primaryColor.withOpacity(0.6), fontWeight: FontsManager.bold, fontSize: 30, height: 0), @@ -140,10 +159,14 @@ class AcInterfaceTempUnit extends StatelessWidget { dimension: 24, child: InkWell( onTap: () { - // DevicesCubit.getInstance() - // .setACTemp(DeviceModel, DeviceModel.coolTo); - // DeviceModel.coolTo += .5; - + if (state is GetDeviceStatusLoading && + state.code == 'temp_set' || + state is DeviceControlSuccess && + state.code == 'temp_set' || + state is DeviceControlLoading && + state.code == 'temp_set') { + return; + } if (setToTemp < 30) { DevicesCubit.getInstance().deviceControl( DeviceControlModel(