mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
refactor: update function handling in routine dialogs
This commit is contained in:
@ -117,10 +117,22 @@ class ACHelper {
|
||||
},
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
final selectedFunctionData =
|
||||
state.addedFunctions.firstWhere(
|
||||
(f) =>
|
||||
f.functionCode == state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
|
||||
/// add the functions to the routine bloc
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
uniqueCustomId,
|
||||
),
|
||||
);
|
||||
|
@ -78,12 +78,22 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
final selectedFunctionData =
|
||||
state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
final functions = _updateValuesForAddedFunctions(
|
||||
state.addedFunctions,
|
||||
);
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
functions,
|
||||
[selectedFunctionData],
|
||||
'${widget.uniqueCustomId}',
|
||||
),
|
||||
);
|
||||
|
@ -192,9 +192,18 @@ class _WallPresenceSensorState extends State<FlushPresenceSensor> {
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
widget.uniqueCustomId!,
|
||||
),
|
||||
);
|
||||
|
@ -115,9 +115,18 @@ class _GatewayDialogState extends State<GatewayDialog> {
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
widget.uniqueCustomId ?? '-1',
|
||||
),
|
||||
);
|
||||
|
@ -147,7 +147,7 @@ class OneGangSwitchHelper {
|
||||
// }
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
uniqueCustomId,
|
||||
),
|
||||
);
|
||||
|
@ -250,9 +250,18 @@ class _EnergyClampDialogState extends State<EnergyClampDialog> {
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
widget.uniqueCustomId!,
|
||||
),
|
||||
);
|
||||
|
@ -27,17 +27,16 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final selectedFn =
|
||||
functions.firstWhere((f) => f.code == selectedFunction);
|
||||
final selectedFn = functions.firstWhere((f) => f.code == selectedFunction);
|
||||
final values = selectedFn.getOperationalValues();
|
||||
final step = selectedFn.step ?? 1.0;
|
||||
final step = selectedFn.step;
|
||||
final _unit = selectedFn.unit ?? '';
|
||||
final (double, double) sliderRange =
|
||||
(selectedFn.min ?? 0.0, selectedFn.max ?? 100.0);
|
||||
|
||||
if (_isSliderFunction(selectedFunction)) {
|
||||
return CustomRoutinesTextbox(
|
||||
withSpecialChar: false,
|
||||
withSpecialChar: true,
|
||||
currentCondition: functionData.condition,
|
||||
dialogType: dialogType,
|
||||
sliderRange: sliderRange,
|
||||
@ -60,14 +59,14 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectedFunction,
|
||||
operationName: functionData.operationName,
|
||||
value: value.toInt(),
|
||||
value: value,
|
||||
condition: functionData.condition,
|
||||
),
|
||||
),
|
||||
),
|
||||
unit: _unit,
|
||||
dividendOfRange: 1,
|
||||
stepIncreaseAmount: step,
|
||||
stepIncreaseAmount: step!,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -145,9 +145,22 @@ class TwoGangSwitchHelper {
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
final selectedFunctionData =
|
||||
state.addedFunctions.firstWhere(
|
||||
(f) =>
|
||||
f.functionCode ==
|
||||
state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode:
|
||||
state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
uniqueCustomId,
|
||||
),
|
||||
);
|
||||
|
@ -210,9 +210,18 @@ class _WallPresenceSensorState extends State<WallPresenceSensor> {
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
widget.uniqueCustomId!,
|
||||
),
|
||||
);
|
||||
|
@ -188,9 +188,18 @@ class _WaterHeaterDialogRoutinesState extends State<WaterHeaterDialogRoutines> {
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == state.selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: state.selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
[selectedFunctionData],
|
||||
widget.uniqueCustomId!,
|
||||
),
|
||||
);
|
||||
|
Reference in New Issue
Block a user