I implemented Flutter Slider in my project, it's looking same as documentation, but slider is only reacting to click on one of division, when I tried to drag it and move it's not moving.
Here is my code:
Stack(
alignment: AlignmentDirectional.topCenter,
children: [
Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.05),
child: Slider(
max: 30,
min: 1,
divisions: 6,
activeColor: Theme.of(context)
.primaryColor,
label: helperDistance!
.floor()
.toString() 'km',
value: helperDistance!,
onChanged: (newValue) {
print(newValue);
setState(() =>
helperDistance = newValue);
},
),
),
AutoSizeText(helperDistance!.floor().toString() ' km'),
],
)
What is wrong actually here?
EDIT: I was using Flutter 3.0, upgrading Flutter to 3.0.5 solved the problem
CodePudding user response:
It is working correctly if your variable is in the build method int that case it wont work because the build method is called every time you call the setState method and the value of the variable becomes the default again. if that is the case move that variable above the build method and it will work.
CodePudding user response:
Problem solved, it was problem with Flutter 3.0, upgrading to 3.0.5 solved the problem.