Files
syncrow-web/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart
2024-11-24 01:10:31 +03:00

69 lines
2.2 KiB
Dart

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<Map<String, dynamic>?> showDeviceDialog(
BuildContext context,
Map<String, dynamic> data,
) async {
final functions = data['functions'] as List<DeviceFunction>;
try {
final result = await _getDialogForDeviceType(
context,
data['productType'],
data,
functions,
);
if (result != null) {
return result;
}
} catch (e) {
debugPrint('Error: $e');
}
return null;
}
static Future<Map<String, dynamic>?> _getDialogForDeviceType(
BuildContext context,
String productType,
Map<String, dynamic> data,
List<DeviceFunction> functions,
) async {
final routineBloc = context.read<RoutineBloc>();
final deviceSelectedFunctions =
routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? [];
switch (productType) {
case 'AC':
return ACHelper.showACFunctionsDialog(context, functions,
data['device'], deviceSelectedFunctions, data['uniqueCustomId']);
case '1G':
return OneGangSwitchHelper.showSwitchFunctionsDialog(context, functions,
data['device'], deviceSelectedFunctions, data['uniqueCustomId']);
case '2G':
return TwoGangSwitchHelper.showSwitchFunctionsDialog(context, functions,
data['device'], deviceSelectedFunctions, data['uniqueCustomId']);
case '3G':
return ThreeGangSwitchHelper.showSwitchFunctionsDialog(
context,
functions,
data['device'],
deviceSelectedFunctions,
data['uniqueCustomId'],
);
default:
return null;
}
}
}