@override
Widget build(BuildContext context) {
double currentSliderValue = 100.0;
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Slider(
value: currentSliderValue,
onChanged: (double value) {
setState(() {
currentSliderValue = value;
});
},
label: '$currentSliderValue',
),
),
);
}
}
I tyied to make a slider , its very similir as other example, its value could be changed, but didnt move at all
2
Answers
the problem is that you initialize the value inside the build method, which is called every time the widget is rendered, as with setState.
Just change to this
The slider holds values from 0 to 1.
And your initial value is 100. Which is giving you the error.
Here is your working code.