Refactor SliderValueSelector and ValueDisplay to include unit handling and improve UI consistency across sensor dialogs.

This commit is contained in:
Faris Armoush
2025-04-10 16:22:02 +03:00
parent fadb23d631
commit 74046c5aed
4 changed files with 145 additions and 39 deletions

View File

@ -29,13 +29,12 @@ class CpsDialogSliderSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SliderValueSelector(
selectedFunction: selectedFunction,
functionData: selectedFunctionData,
device: device,
currentCondition: selectedFunctionData.condition,
dialogType: dialogType,
sliderRange: _sliderRange,
displayedValue: _displayText,
initialValue: selectedFunctionData.value ?? 0,
unit: _unit,
onConditionChanged: (condition) => context.read<FunctionBloc>().add(
AddFunction(
functionData: DeviceFunctionData(
@ -58,13 +57,10 @@ class CpsDialogSliderSelector extends StatelessWidget {
),
),
),
);
}
double get sliderStepper {
return 1;
}
(double, double) get _sliderRange => switch (selectedFunctionData.functionCode) {
'moving_speed' => (0, 32),
'space_static_val' => (0, 255),
@ -94,12 +90,26 @@ class CpsDialogSliderSelector extends StatelessWidget {
'presence_range' ||
'perceptual_boundary' ||
'moving_boundary' =>
'${parsedValue?.toStringAsFixed(1) ?? '0'} M',
'moving_rigger_time' => '${parsedValue?.toStringAsFixed(3) ?? '0'} s',
'${parsedValue?.toStringAsFixed(1) ?? '0'}',
'moving_rigger_time' => '${parsedValue?.toStringAsFixed(3) ?? '0'}',
'moving_static_time' ||
'none_body_time' =>
'${parsedValue?.toStringAsFixed(0) ?? '0'} s',
'${parsedValue?.toStringAsFixed(0) ?? '0'}',
_ => '${parsedValue ?? 0}',
};
}
String get _unit {
return switch (selectedFunctionData.functionCode) {
'moving_max_dis' ||
'static_max_dis' ||
'moving_range' ||
'presence_range' ||
'perceptual_boundary' ||
'moving_boundary' =>
'M',
'moving_rigger_time' || 'moving_static_time' || 'none_body_time' => 'sec',
_ => '',
};
}
}

View File

@ -32,9 +32,7 @@ class WpsValueSelectorWidget extends StatelessWidget {
if (_isSliderFunction(selectedFunction)) {
return SliderValueSelector(
selectedFunction: selectedFunction,
functionData: functionData,
device: device,
currentCondition: functionData.condition,
dialogType: dialogType,
sliderRange: sliderRange,
displayedValue: getDisplayText,
@ -61,6 +59,7 @@ class WpsValueSelectorWidget extends StatelessWidget {
),
),
),
unit: _unit,
);
}
@ -86,10 +85,17 @@ class WpsValueSelectorWidget extends StatelessWidget {
String get getDisplayText {
final intValue = int.tryParse('${functionData.value ?? ''}');
return switch (functionData.functionCode) {
'presence_time' => '${intValue ?? '0'} Min',
'dis_current' => '${intValue ?? '250'} CM',
'illuminance_value' => '${intValue ?? '0'} Lux',
'presence_time' => '${intValue ?? '0'}',
'dis_current' => '${intValue ?? '250'}',
'illuminance_value' => '${intValue ?? '0'}',
_ => '$intValue',
};
}
String get _unit => switch (functionData.functionCode) {
'presence_time' => 'Min',
'dis_current' => 'CM',
'illuminance_value' => 'Lux',
_ => '',
};
}