mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
191 lines
8.1 KiB
Dart
191 lines
8.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
|
import 'package:syncrow_web/pages/routiens/models/ac/ac_function.dart';
|
|
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
|
|
mixin ACHelper {
|
|
Future<Map<String, dynamic>?> showACFunctionsDialog(BuildContext context, List<DeviceFunction<dynamic>> functions) {
|
|
List<ACFunction> acFunctions = functions.whereType<ACFunction>().toList();
|
|
String? selectedFunction;
|
|
dynamic selectedValue;
|
|
|
|
return showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return StatefulBuilder(
|
|
builder: (context, setState) {
|
|
return AlertDialog(
|
|
contentPadding: EdgeInsets.zero,
|
|
content: Container(
|
|
width: selectedFunction != null ? 600 : 360,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
padding: const EdgeInsets.only(top: 20),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
'AC Functions',
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
color: ColorsManager.primaryColorWithOpacity,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 50),
|
|
child: Container(
|
|
height: 1,
|
|
width: double.infinity,
|
|
color: ColorsManager.greyColor,
|
|
),
|
|
),
|
|
Flexible(
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: ListView.separated(
|
|
shrinkWrap: true,
|
|
itemCount: acFunctions.length,
|
|
separatorBuilder: (context, index) => Divider(),
|
|
itemBuilder: (context, index) {
|
|
final function = acFunctions[index];
|
|
return ListTile(
|
|
leading: Image.asset(function.icon, width: 24, height: 24),
|
|
title: Text(function.operationName),
|
|
trailing: Icon(Icons.arrow_forward_ios),
|
|
onTap: () {
|
|
setState(() {
|
|
selectedFunction = function.code;
|
|
selectedValue = null;
|
|
});
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
if (selectedFunction != null)
|
|
Container(
|
|
width: 1,
|
|
color: ColorsManager.greyColor,
|
|
),
|
|
if (selectedFunction != null)
|
|
Expanded(
|
|
child: ListView.separated(
|
|
shrinkWrap: true,
|
|
itemCount: acFunctions
|
|
.firstWhere((f) => f.code == selectedFunction)
|
|
.getOperationalValues()
|
|
.length,
|
|
separatorBuilder: (context, index) => Divider(),
|
|
itemBuilder: (context, index) {
|
|
final operationalValue = acFunctions.firstWhere((f) => f.code == selectedFunction)
|
|
..getOperationalValues()[index];
|
|
return ListTile(
|
|
leading: Image.asset(operationalValue.icon, width: 24, height: 24),
|
|
title: Text(operationalValue.getOperationalValues()[index].description),
|
|
trailing: Radio<dynamic>(
|
|
value: operationalValue.getOperationalValues()[index].value,
|
|
groupValue: selectedValue,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
selectedValue = value;
|
|
});
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
height: 1,
|
|
width: double.infinity,
|
|
color: ColorsManager.greyColor,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.pop(context);
|
|
},
|
|
child: Center(
|
|
child: Text(
|
|
'Cancel',
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: ColorsManager.greyColor),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
height: 50,
|
|
width: 1,
|
|
color: ColorsManager.greyColor,
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
// Handle the confirmation action here
|
|
Navigator.pop(context, {
|
|
'function': selectedFunction,
|
|
'value': selectedValue,
|
|
});
|
|
},
|
|
child: Center(
|
|
child: Text(
|
|
'Confirm',
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
color: ColorsManager.primaryColorWithOpacity,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void handleACDeviceDrop(BuildContext context, Map<String, dynamic> data) {
|
|
final device = data['device'] as AllDevicesModel;
|
|
final acFunctions = device.deviceFunctions;
|
|
|
|
showACFunctionsDialog(context, acFunctions).then((result) {
|
|
if (result != null) {
|
|
_addACDeviceToRoutine(context, data, result);
|
|
}
|
|
});
|
|
}
|
|
|
|
void handleNonACDeviceDrop(BuildContext context, Map<String, dynamic> data) {
|
|
context.read<RoutineBloc>().add(AddToThenContainer(data));
|
|
}
|
|
|
|
void _addACDeviceToRoutine(BuildContext context, Map<String, dynamic> deviceData, Map<String, dynamic> functionData) {
|
|
final updatedData = {
|
|
...deviceData,
|
|
'function': functionData['function'],
|
|
'value': functionData['value'],
|
|
};
|
|
|
|
context.read<RoutineBloc>().add(AddToThenContainer(updatedData));
|
|
|
|
_logACFunctionSelection(functionData);
|
|
}
|
|
|
|
void _logACFunctionSelection(Map<String, dynamic> functionData) {
|
|
print('Selected AC function: ${functionData['function']}, Value: ${functionData['value']}');
|
|
}
|
|
}
|