So I want to build a slider where users can choose a value between 100-1000 and the value should be like this 100,150,200,250... 950,1000 but I noticed that I get values like 499.9999994 or 500.000001. Any idea how can I fix this?
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('100'),
CupertinoSlider(
value: context.watch<LoanValue>().value,
min: 100,
max: 1000,
divisions: 18,
onChanged: (double value) {
context.read<LoanValue>().updateValue(value);
},
),
Text('1000'),
],
),
this is where I update the value:
class LoanValue with ChangeNotifier, DiagnosticableTreeMixin {
double loanValue = 100;
double get value => loanValue;
void updateValue(double division) {
loanValue = division;
// debugPrint('loanValue: $loanValue');
notifyListeners();
}
}
I fixed this by adding this
.roundToDouble()