mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
add step parameter in onTapFunction.
Add dialogType parameter in WaterHeaterPresenceSensor and CeilingSensorDialog. Update step parameter in FlushValueSelectorWidget. Update step parameter in FunctionBloc and WaterHeaterFunctions. Update step, unit, min, and max parameters in ACFunction subclasses.
This commit is contained in:
@ -7,6 +7,7 @@ import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/ac/ac_operational_value.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/custom_routines_textbox.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/helpers/routine_tap_function_helper.dart';
|
||||
@ -76,24 +77,20 @@ class ACHelper {
|
||||
context: context,
|
||||
acFunctions: acFunctions,
|
||||
device: device,
|
||||
onFunctionSelected: (functionCode, operationName) {
|
||||
onFunctionSelected:
|
||||
(functionCode, operationName) {
|
||||
RoutineTapFunctionHelper.onTapFunction(
|
||||
context,
|
||||
functionCode: functionCode,
|
||||
functionOperationName: operationName,
|
||||
functionValueDescription:
|
||||
selectedFunctionData.valueDescription,
|
||||
deviceUuid: device?.uuid,
|
||||
codesToAddIntoFunctionsWithDefaultValue: [
|
||||
'temp_set',
|
||||
'temp_current',
|
||||
],
|
||||
defaultValue: functionCode == 'temp_set'
|
||||
? 200
|
||||
: functionCode == 'temp_current'
|
||||
? -100
|
||||
: 0,
|
||||
);
|
||||
context,
|
||||
functionCode: functionCode,
|
||||
functionOperationName: operationName,
|
||||
functionValueDescription:
|
||||
selectedFunctionData.valueDescription,
|
||||
deviceUuid: device?.uuid,
|
||||
codesToAddIntoFunctionsWithDefaultValue: [
|
||||
'temp_set',
|
||||
'temp_current',
|
||||
],
|
||||
defaultValue: 0);
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -206,27 +203,61 @@ class ACHelper {
|
||||
required String operationName,
|
||||
bool? removeComparators,
|
||||
}) {
|
||||
final initialVal = selectedFunction == 'temp_set' ? 200 : -100;
|
||||
final selectedFn =
|
||||
acFunctions.firstWhere((f) => f.code == selectedFunction);
|
||||
|
||||
if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') {
|
||||
final initialValue = selectedFunctionData?.value ?? initialVal;
|
||||
return _buildTemperatureSelector(
|
||||
context: context,
|
||||
initialValue: initialValue,
|
||||
selectCode: selectedFunction,
|
||||
// Convert stored integer value to display value
|
||||
final displayValue =
|
||||
(selectedFunctionData?.value ?? selectedFn.min ?? 0) / 10;
|
||||
final minValue = selectedFn.min! / 10;
|
||||
final maxValue = selectedFn.max! / 10;
|
||||
return CustomRoutinesTextbox(
|
||||
withSpecialChar: true,
|
||||
dividendOfRange: maxValue,
|
||||
currentCondition: selectedFunctionData?.condition,
|
||||
device: device,
|
||||
operationName: operationName,
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
removeComparators: removeComparators,
|
||||
dialogType: selectedFn.type,
|
||||
sliderRange: (minValue, maxValue),
|
||||
displayedValue: displayValue.toStringAsFixed(1),
|
||||
initialValue: displayValue.toDouble(),
|
||||
unit: selectedFn.unit!,
|
||||
onConditionChanged: (condition) => context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectedFunction,
|
||||
operationName: selectedFn.operationName,
|
||||
condition: condition,
|
||||
value: 0,
|
||||
step: selectedFn.step,
|
||||
unit: selectedFn.unit,
|
||||
max: selectedFn.max,
|
||||
min: selectedFn.min,
|
||||
),
|
||||
),
|
||||
),
|
||||
onTextChanged: (value) => context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectedFunction,
|
||||
operationName: selectedFn.operationName,
|
||||
value: (value * 10).round(), // Store as integer
|
||||
condition: selectedFunctionData?.condition,
|
||||
step: selectedFn.step,
|
||||
unit: selectedFn.unit,
|
||||
max: selectedFn.max,
|
||||
min: selectedFn.min,
|
||||
),
|
||||
),
|
||||
),
|
||||
stepIncreaseAmount: selectedFn.step! / 10, // Convert step for display
|
||||
);
|
||||
}
|
||||
|
||||
final selectedFn = acFunctions.firstWhere((f) => f.code == selectedFunction);
|
||||
final values = selectedFn.getOperationalValues();
|
||||
|
||||
return _buildOperationalValuesList(
|
||||
context: context,
|
||||
values: values,
|
||||
values: selectedFn.getOperationalValues(),
|
||||
selectedValue: selectedFunctionData?.value,
|
||||
device: device,
|
||||
operationName: operationName,
|
||||
@ -235,150 +266,151 @@ class ACHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/// Build temperature selector for AC functions dialog
|
||||
static Widget _buildTemperatureSelector({
|
||||
required BuildContext context,
|
||||
required dynamic initialValue,
|
||||
required String? currentCondition,
|
||||
required String selectCode,
|
||||
AllDevicesModel? device,
|
||||
required String operationName,
|
||||
DeviceFunctionData? selectedFunctionData,
|
||||
bool? removeComparators,
|
||||
}) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (removeComparators != true)
|
||||
_buildConditionToggle(
|
||||
context,
|
||||
currentCondition,
|
||||
selectCode,
|
||||
device,
|
||||
operationName,
|
||||
selectedFunctionData,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildTemperatureDisplay(
|
||||
context,
|
||||
initialValue,
|
||||
device,
|
||||
operationName,
|
||||
selectedFunctionData,
|
||||
selectCode,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildTemperatureSlider(
|
||||
context,
|
||||
initialValue,
|
||||
device,
|
||||
operationName,
|
||||
selectedFunctionData,
|
||||
selectCode,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
// /// Build temperature selector for AC functions dialog
|
||||
// static Widget _buildTemperatureSelector({
|
||||
// required BuildContext context,
|
||||
// required dynamic initialValue,
|
||||
// required String? currentCondition,
|
||||
// required String selectCode,
|
||||
// AllDevicesModel? device,
|
||||
// required String operationName,
|
||||
// DeviceFunctionData? selectedFunctionData,
|
||||
// bool? removeComparators,
|
||||
// }) {
|
||||
// return Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// if (removeComparators != true)
|
||||
// _buildConditionToggle(
|
||||
// context,
|
||||
// currentCondition,
|
||||
// selectCode,
|
||||
// device,
|
||||
// operationName,
|
||||
// selectedFunctionData,
|
||||
// ),
|
||||
// const SizedBox(height: 20),
|
||||
// _buildTemperatureDisplay(
|
||||
// context,
|
||||
// initialValue,
|
||||
// device,
|
||||
// operationName,
|
||||
// selectedFunctionData,
|
||||
// selectCode,
|
||||
// ),
|
||||
// const SizedBox(height: 20),
|
||||
// _buildTemperatureSlider(
|
||||
// context,
|
||||
// initialValue,
|
||||
// device,
|
||||
// operationName,
|
||||
// selectedFunctionData,
|
||||
// selectCode,
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
/// Build condition toggle for AC functions dialog
|
||||
static Widget _buildConditionToggle(
|
||||
BuildContext context,
|
||||
String? currentCondition,
|
||||
String selectCode,
|
||||
AllDevicesModel? device,
|
||||
String operationName,
|
||||
DeviceFunctionData? selectedFunctionData,
|
||||
// /// Build condition toggle for AC functions dialog
|
||||
// static Widget _buildConditionToggle(
|
||||
// BuildContext context,
|
||||
// String? currentCondition,
|
||||
// String selectCode,
|
||||
// AllDevicesModel? device,
|
||||
// String operationName,
|
||||
// DeviceFunctionData? selectedFunctionData,
|
||||
|
||||
// Function(String) onConditionChanged,
|
||||
) {
|
||||
final conditions = ["<", "==", ">"];
|
||||
// // Function(String) onConditionChanged,
|
||||
// ) {
|
||||
// final conditions = ["<", "==", ">"];
|
||||
|
||||
return ToggleButtons(
|
||||
onPressed: (int index) {
|
||||
context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectCode,
|
||||
operationName: operationName,
|
||||
condition: conditions[index],
|
||||
value: selectedFunctionData?.value ?? selectCode == 'temp_set'
|
||||
? 200
|
||||
: -100,
|
||||
valueDescription: selectedFunctionData?.valueDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
selectedBorderColor: ColorsManager.primaryColorWithOpacity,
|
||||
selectedColor: Colors.white,
|
||||
fillColor: ColorsManager.primaryColorWithOpacity,
|
||||
color: ColorsManager.primaryColorWithOpacity,
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 40.0,
|
||||
minWidth: 40.0,
|
||||
),
|
||||
isSelected: conditions.map((c) => c == (currentCondition ?? "==")).toList(),
|
||||
children: conditions.map((c) => Text(c)).toList(),
|
||||
);
|
||||
}
|
||||
// return ToggleButtons(
|
||||
// onPressed: (int index) {
|
||||
// context.read<FunctionBloc>().add(
|
||||
// AddFunction(
|
||||
// functionData: DeviceFunctionData(
|
||||
// entityId: device?.uuid ?? '',
|
||||
// functionCode: selectCode,
|
||||
// operationName: operationName,
|
||||
// condition: conditions[index],
|
||||
// value: selectedFunctionData?.value ?? selectCode == 'temp_set'
|
||||
// ? 200
|
||||
// : -100,
|
||||
// valueDescription: selectedFunctionData?.valueDescription,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
// selectedBorderColor: ColorsManager.primaryColorWithOpacity,
|
||||
// selectedColor: Colors.white,
|
||||
// fillColor: ColorsManager.primaryColorWithOpacity,
|
||||
// color: ColorsManager.primaryColorWithOpacity,
|
||||
// constraints: const BoxConstraints(
|
||||
// minHeight: 40.0,
|
||||
// minWidth: 40.0,
|
||||
// ),
|
||||
// isSelected:
|
||||
// conditions.map((c) => c == (currentCondition ?? "==")).toList(),
|
||||
// children: conditions.map((c) => Text(c)).toList(),
|
||||
// );
|
||||
// }
|
||||
|
||||
/// Build temperature display for AC functions dialog
|
||||
static Widget _buildTemperatureDisplay(
|
||||
BuildContext context,
|
||||
dynamic initialValue,
|
||||
AllDevicesModel? device,
|
||||
String operationName,
|
||||
DeviceFunctionData? selectedFunctionData,
|
||||
String selectCode,
|
||||
) {
|
||||
final initialVal = selectCode == 'temp_set' ? 200 : -100;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.primaryColorWithOpacity.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${(initialValue ?? initialVal) / 10}°C',
|
||||
style: context.textTheme.headlineMedium!.copyWith(
|
||||
color: ColorsManager.primaryColorWithOpacity,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
// /// Build temperature display for AC functions dialog
|
||||
// static Widget _buildTemperatureDisplay(
|
||||
// BuildContext context,
|
||||
// dynamic initialValue,
|
||||
// AllDevicesModel? device,
|
||||
// String operationName,
|
||||
// DeviceFunctionData? selectedFunctionData,
|
||||
// String selectCode,
|
||||
// ) {
|
||||
// final initialVal = selectCode == 'temp_set' ? 200 : -100;
|
||||
// return Container(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
// decoration: BoxDecoration(
|
||||
// color: ColorsManager.primaryColorWithOpacity.withOpacity(0.1),
|
||||
// borderRadius: BorderRadius.circular(10),
|
||||
// ),
|
||||
// child: Text(
|
||||
// '${(initialValue ?? initialVal) / 10}°C',
|
||||
// style: context.textTheme.headlineMedium!.copyWith(
|
||||
// color: ColorsManager.primaryColorWithOpacity,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
static Widget _buildTemperatureSlider(
|
||||
BuildContext context,
|
||||
dynamic initialValue,
|
||||
AllDevicesModel? device,
|
||||
String operationName,
|
||||
DeviceFunctionData? selectedFunctionData,
|
||||
String selectCode,
|
||||
) {
|
||||
return Slider(
|
||||
value: initialValue is int ? initialValue.toDouble() : 200.0,
|
||||
min: selectCode == 'temp_current' ? -100 : 200,
|
||||
max: selectCode == 'temp_current' ? 900 : 300,
|
||||
divisions: 10,
|
||||
label: '${((initialValue ?? 160) / 10).toInt()}°C',
|
||||
onChanged: (value) {
|
||||
context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectCode,
|
||||
operationName: operationName,
|
||||
value: value,
|
||||
condition: selectedFunctionData?.condition,
|
||||
valueDescription: selectedFunctionData?.valueDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
// static Widget _buildTemperatureSlider(
|
||||
// BuildContext context,
|
||||
// dynamic initialValue,
|
||||
// AllDevicesModel? device,
|
||||
// String operationName,
|
||||
// DeviceFunctionData? selectedFunctionData,
|
||||
// String selectCode,
|
||||
// ) {
|
||||
// return Slider(
|
||||
// value: initialValue is int ? initialValue.toDouble() : 200.0,
|
||||
// min: selectCode == 'temp_current' ? -100 : 200,
|
||||
// max: selectCode == 'temp_current' ? 900 : 300,
|
||||
// divisions: 10,
|
||||
// label: '${((initialValue ?? 160) / 10).toInt()}°C',
|
||||
// onChanged: (value) {
|
||||
// context.read<FunctionBloc>().add(
|
||||
// AddFunction(
|
||||
// functionData: DeviceFunctionData(
|
||||
// entityId: device?.uuid ?? '',
|
||||
// functionCode: selectCode,
|
||||
// operationName: operationName,
|
||||
// value: value,
|
||||
// condition: selectedFunctionData?.condition,
|
||||
// valueDescription: selectedFunctionData?.valueDescription,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
|
||||
static Widget _buildOperationalValuesList({
|
||||
required BuildContext context,
|
||||
@ -414,7 +446,9 @@ class ACHelper {
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
trailing: Icon(
|
||||
isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
||||
isSelected
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_unchecked,
|
||||
size: 24,
|
||||
color: isSelected
|
||||
? ColorsManager.primaryColorWithOpacity
|
||||
@ -430,7 +464,8 @@ class ACHelper {
|
||||
operationName: operationName,
|
||||
value: value.value,
|
||||
condition: selectedFunctionData?.condition,
|
||||
valueDescription: selectedFunctionData?.valueDescription,
|
||||
valueDescription:
|
||||
selectedFunctionData?.valueDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
Reference in New Issue
Block a user