mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
86 lines
2.6 KiB
Dart
86 lines
2.6 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/widgets/routine_dialogs/ac_dialog.dart';
|
|
import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart';
|
|
import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart';
|
|
import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.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, {
|
|
required bool removeComparetors,
|
|
}) async {
|
|
final functions = data['functions'] as List<DeviceFunction>;
|
|
|
|
try {
|
|
final result = await _getDialogForDeviceType(
|
|
context,
|
|
data['productType'],
|
|
data,
|
|
functions,
|
|
removeComparetors: removeComparetors,
|
|
);
|
|
|
|
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,
|
|
{required bool removeComparetors}) 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'],
|
|
removeComparetors);
|
|
|
|
case '1G':
|
|
return OneGangSwitchHelper.showSwitchFunctionsDialog(
|
|
context,
|
|
functions,
|
|
data['device'],
|
|
deviceSelectedFunctions,
|
|
data['uniqueCustomId'],
|
|
removeComparetors);
|
|
case '2G':
|
|
return TwoGangSwitchHelper.showSwitchFunctionsDialog(
|
|
context,
|
|
functions,
|
|
data['device'],
|
|
deviceSelectedFunctions,
|
|
data['uniqueCustomId'],
|
|
removeComparetors);
|
|
case '3G':
|
|
return ThreeGangSwitchHelper.showSwitchFunctionsDialog(
|
|
context,
|
|
functions,
|
|
data['device'],
|
|
deviceSelectedFunctions,
|
|
data['uniqueCustomId'],
|
|
removeComparetors);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
}
|