Reputation: 648
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.
I looked at https://pub.dev/packages/flutter_xlider but it seems like that package also required values to be set.
Upvotes: 0
Views: 1166
Reputation: 491
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.
Upvotes: 0