How to set an empty initial value for Flutter Slider?

904 Views Asked by At

Currently the "value" property of Slider is required, however I was wondering if it is possible to create a Slider such that it initially has no value and the thumb is hidden. Then when the user presses along the line, the thumb appears at that point. Above is what I want the initial state of the slider to look like, below is what it currently looks like as I set value to min as value is required

I looked at https://pub.dev/packages/flutter_xlider but it seems like that package also required values to be set.

1

There are 1 best solutions below

0
On

I think not, and for good reason. The function of the Slider and the understanding of how it is used is interpreted by the user primarily based on seeing the thumb indicator on a line. So regardless how you set up the requirements for the slider's usage in your app, the Slider control needs to always have a value represented. You could default the slider value to the min, the max, the middle(-ish), or any valid value.

If you want to ensure the user makes a selection (making it a required field sort of), you could set a bool state variable on an ancestor widget (perhaps named sliderWasTouched) to true when any part of the Slider is tapped and whenever the Slider changes value (after initialization), and then make that state variable being true part of your form field validation.