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
@@ -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',
_ => '',
};
}
}