I'm hoping to render a flutter slider that is unmovable, meaning that I hope to pass the slider an initial value that the user will not be able to change purely for UI visualization?
Has anyone had any experience locking this slider in place?
Thanks for the help.
In flutter, most widgets already come with an option to disable them for example in a RaisedButton we can set the onClicked function to null to disable, or we can use NeverScrollableScrollPhysics( ) to disable a ListView.
Customizing the slider color The basic Slider widget gives you access to three properties for setting its color: activeColor : Applies color to the active portion of the slider track. inactiveColor : Applies color to the inactive portion of the slider track. thumbColor : Applies color to the slider thumb.
A slider can be used to select from either a continuous or a discrete set of values. The default is to use a continuous range of values from min to max. To use discrete values, use a non-null value for divisions, which indicates the number of discrete intervals.
Try set up divisions value to 9. You will see the label on each step of the values.
Give it a value and then set the onChanged:
property to null.
onChanged: null
This disables the Slider.
Otherwise, you could give max:
and min:
the same value. In this case, though, the slider is not greyed out but it stays at zero.
Just wrap an AbsorbPointer around your slider like so:
AbsorbPointer(
child: Slider(
onChanged: (value) => print(value),
min: 0,
max: 100,
divisions: 10,
value: 30,
),
)
In order to have your SliderTheme
affect a disabled slider you have to overwrite the disabled
attributes.
Here is a quick example:
SliderTheme(
data: SliderTheme.of(context).copyWith(
disabledActiveTrackColor: Colors.red[700],
disabledInactiveTrackColor: Colors.red[100],
disabledThumbColor: Colors.redAccent,
),
child: Slider(
value: 0.2,
onChanged: null,
),
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With