From fd6b737556bb134bf0795319cd2458e6150da3c3 Mon Sep 17 00:00:00 2001 From: mohammad Date: Wed, 9 Apr 2025 12:17:26 +0300 Subject: [PATCH] Refactor one_gang_switch_dialog.dart to use one_gang_switch instead of ac in function names and variables --- .../one_gang_switch_dialog.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart index 4fe87da3..d0fcde28 100644 --- a/lib/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart @@ -5,8 +5,10 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart'; import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/pages/routines/helper/duration_format_helper.dart'; +import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart'; import 'package:syncrow_web/pages/routines/models/device_functions.dart'; import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart'; import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; @@ -23,7 +25,7 @@ class OneGangSwitchHelper { required String uniqueCustomId, required bool removeComparetors, }) async { - List acFunctions = + List oneGangFunctions = functions.whereType().toList(); return showDialog?>( @@ -64,12 +66,12 @@ class OneGangSwitchHelper { // Left side: Function list Expanded( child: ListView.separated( - itemCount: acFunctions.length, + itemCount: oneGangFunctions.length, separatorBuilder: (_, __) => const Divider( color: ColorsManager.dividerColor, ), itemBuilder: (context, index) { - final function = acFunctions[index]; + final function = oneGangFunctions[index]; return ListTile( leading: SvgPicture.asset( function.icon, @@ -105,7 +107,7 @@ class OneGangSwitchHelper { context: context, selectedFunction: selectedFunction, selectedFunctionData: selectedFunctionData, - acFunctions: acFunctions, + acFunctions: oneGangFunctions, device: device, operationName: selectedOperationName ?? '', removeComparetors: removeComparetors, @@ -180,9 +182,14 @@ class OneGangSwitchHelper { removeComparetors: removeComparetors, ); } + final selectedFn = acFunctions.firstWhere( + (f) => f.code == selectedFunction, + orElse: () => OneGangSwitchFunction( + deviceId: '', + deviceName: '', + ), + ); - final selectedFn = - acFunctions.firstWhere((f) => f.code == selectedFunction); final values = selectedFn.getOperationalValues(); return _buildOperationalValuesList(