Add dividendOfRange parameter to FunctionSlider and related components for improved range handling

This commit is contained in:
Faris Armoush
2025-04-13 10:09:39 +03:00
parent 828db5d5e4
commit 60a1a9ad6f
4 changed files with 41 additions and 7 deletions

View File

@ -2,25 +2,34 @@ import 'package:flutter/material.dart';
class FunctionSlider extends StatelessWidget {
final dynamic initialValue;
final (double min, double max) range;
final void Function(double value) onChanged;
final double dividendOfRange;
const FunctionSlider({
required this.onChanged,
required this.initialValue,
required this.range,
required this.dividendOfRange,
super.key,
});
@override
Widget build(BuildContext context) {
final (min, max) = range;
final bool isValidRange = max > min;
final double value = initialValue is int
? (initialValue as int).toDouble()
: (initialValue as double);
final int? divisions = isValidRange ? ((max - min) / dividendOfRange).round() : null;
return Slider(
value: initialValue is int ? initialValue.toDouble() : range.$1,
min: range.$1,
max: range.$2,
divisions: (range.$2 - range.$1).toInt(),
onChanged: onChanged,
value: value.clamp(min, max),
min: min,
max: max,
divisions: divisions,
onChanged: isValidRange ? onChanged : null,
);
}
}

View File

@ -52,11 +52,12 @@ class CpsDialogSliderSelector extends StatelessWidget {
entityId: device?.uuid ?? '',
functionCode: selectedFunction,
operationName: selectedFunctionData.operationName,
value: value.toInt(),
value: value,
condition: selectedFunctionData.condition,
),
),
),
dividendOfRange: _dividendOfRange,
);
}
@ -111,4 +112,24 @@ class CpsDialogSliderSelector extends StatelessWidget {
_ => '',
};
}
double get _dividendOfRange => switch (selectedFunctionData.functionCode) {
'sensitivity' => 1,
'moving_speed' => 1,
'space_static_val' => 1,
'space_move_val' => 1,
'presence_reference' => 5,
'moving_reference' => 5,
'moving_max_dis' => 0.5,
'static_max_dis' => 0.5,
'moving_range' => 0.1,
'presence_range' => 0.1,
'perceptual_boundary' => 0.5,
'moving_boundary' => 0.5,
'moving_rigger_time' => 0.1,
'moving_static_time' => 1.0,
'none_body_time' => 5.0,
'sports_para' => 1.0,
_ => 1,
};
}

View File

@ -60,6 +60,7 @@ class WpsValueSelectorWidget extends StatelessWidget {
),
),
unit: _unit,
dividendOfRange: 1,
);
}

View File

@ -15,6 +15,7 @@ class SliderValueSelector extends StatelessWidget {
final void Function(String condition) onConditionChanged;
final void Function(double value) onSliderChanged;
final String unit;
final double dividendOfRange;
const SliderValueSelector({
required this.dialogType,
@ -25,6 +26,7 @@ class SliderValueSelector extends StatelessWidget {
required this.onSliderChanged,
required this.currentCondition,
required this.unit,
required this.dividendOfRange,
super.key,
});
@ -48,6 +50,7 @@ class SliderValueSelector extends StatelessWidget {
initialValue: initialValue,
range: sliderRange,
onChanged: onSliderChanged,
dividendOfRange: dividendOfRange,
),
],
);