Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide thumb on flutter Slider Widget?

Tags:

flutter

I have to hide the thumb on Slider widget. I set thumb colour to transparent with SliderTheme widget. It does not work. How to hide thumb?

I set thumb colour to transparent.

Center(
  child: SliderTheme(
    child: Slider(
      value: 50,
      max: 100,
      min: 0,
      activeColor: Colors.black,
      inactiveColor: Colors.grey,
      onChanged: (double value) {},
    ),
    data: SliderTheme.of(context).copyWith(
      trackHeight: 28, 
      thumbColor: Colors.transparent, 
      thumbShape: null),
  ),
)

I expect the slider widget without thumb.

like image 673
Deva Samy Avatar asked Aug 30 '19 09:08

Deva Samy


Video Answer


2 Answers

Bit of a workaround but you can set the thumbShape to have a radius of 0:

Center(
  child: SliderTheme(
    child: Slider(
      value: 50,
      max: 100,
      min: 0,
      activeColor: Colors.black,
      inactiveColor: Colors.grey,
      onChanged: (double value) {},
    ),
    data: SliderTheme.of(context).copyWith(
        trackHeight: 28,
        thumbColor: Colors.transparent,
        thumbShape: RoundSliderThumbShape(enabledThumbRadius: 0.0)),
  ),
),
like image 61
Jordan Davies Avatar answered Nov 16 '22 16:11

Jordan Davies


Not a workaround. The correct way to do it.

Set the thumbShape to SliderComponentShape.noThumb

i.e.

SliderTheme.of(context).copyWith(
    trackHeight: 28,
    thumbShape: SliderComponentShape.noThumb,
like image 26
Simon Hutton Avatar answered Nov 16 '22 17:11

Simon Hutton