I am trying to make range slider where values are loaded before the app is completed and also i am trying to get value from the API, not hardcoded it, so I create such function which should loaded values before app is completed and trying to get values from API, but still facing with issues about cast to types:
static Map? gainMin;
var _currentRangeValues = RangeValues(
num.parse(gainMin?['min']).round().toDouble(),
num.parse(gainMin?['max']).round().toDouble());
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
fetchGains(num.parse(gainMin?['min']).round().toDouble(),
num.parse(gainMin?['max']).round().toDouble());
});
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder<Map?>(
future: fetchGains(_currentRangeValues.start.round().toInt(),
_currentRangeValues.end.round().toInt()),
builder: (context, snapshot) {
print(gainMin);
RangeSlider(
values: RangeValues(num.parse(gainMin?['min']).roundToDouble(),
num.parse(gainMin?['max']).roundToDouble()),
min: num.parse(gainMin?['min']).roundToDouble(),
max: num.parse(gainMin?['max']).roundToDouble(),
activeColor: Colors.green,
inactiveColor: Colors.green,
onChanged: (RangeValues value) {
setState(() {
if (_debounce?.isActive ?? false) _debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 15), () {
snapshot.data?['value'] = value.start;
snapshot.data?['valueMax'] = value.end;
// _currentRangeValues = value;
});
});
},
)
}
}
But I got the error: type 'int' is not a subtype of type 'String' How can i solve this issue?
Print returns {min: 1, max: 22, value: 0.0, valueMax: 0.0, step: 1.0}