import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/pages/routiens/helper/ac_helper.dart'; import 'package:syncrow_web/pages/routiens/helper/one_gang_switch_helper.dart'; import 'package:syncrow_web/pages/routiens/helper/three_gang_switch_helper.dart'; import 'package:syncrow_web/pages/routiens/helper/two_gang_switch_helper.dart'; import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; class DeviceDialogHelper { static Future?> showDeviceDialog( BuildContext context, Map data, ) async { final functions = data['functions'] as List; try { final result = await _getDialogForDeviceType( context, data['productType'], data, functions, ); if (result != null) { return result; } } catch (e) { debugPrint('Error: $e'); } return null; } static Future?> _getDialogForDeviceType( BuildContext context, String productType, Map data, List functions, ) async { final routineBloc = context.read(); final deviceSelectedFunctions = routineBloc.state.selectedFunctions .where((f) => f.entityId == data['deviceId']) .toList(); switch (productType) { case 'AC': return ACHelper.showACFunctionsDialog( context, functions, data['device'], deviceSelectedFunctions); case '1G': return OneGangSwitchHelper.showSwitchFunctionsDialog( context, functions, data['device'], deviceSelectedFunctions); case '2G': return TwoGangSwitchHelper.showSwitchFunctionsDialog( context, functions); case '3G': return ThreeGangSwitchHelper.showSwitchFunctionsDialog( context, functions); default: return null; } } }