Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Remove default padding in Slider

Tags:

flutter

I am wondering how I can remove the default padding in Flutter Slider

Current output is like this, default padding of Slider is clearly visible

enter image description here

Here's my code::

                    Positioned(
                      child: Align(
                        alignment: Alignment.bottomLeft,
                        child: SliderTheme(
                            data: SliderTheme.of(context).copyWith(
                              trackHeight: 2.0,
                              thumbColor: Colors.transparent,
                              thumbShape: RoundSliderThumbShape(enabledThumbRadius: 0.0),
                            ),
                            child: Container(
                                width: 380.0,
                                height: 20.0,
                                padding: EdgeInsets.all(0.0),
                                decoration: BoxDecoration(
                                  border: Border.all(color: Colors.blueAccent)
                                ),
                                child: Slider(
                                  value: 50,
                                  min: 1,
                                  max: 100,
                                  divisions: 100,
                                  activeColor: colors.primaryRed,
                                  inactiveColor: Colors.white,
                                  onChanged: (double newValue) {
                                    print(newValue);
                                  },
                                )
                            )
                        ),
                      ),
                    )
like image 260
CodingWithRoyal Avatar asked Jan 11 '21 03:01

CodingWithRoyal


People also ask

How do you customize slider in flutter?

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.


1 Answers

SliderThemeData(overlayShape: SliderComponentShape.noOverlay)

or

overlayShape: SliderComponentShape.noThumb

Default padding is caused by thumb painting and overlay painting, by specifying these properties you will remove them, but you will get zero padding

https://api.flutter.dev/flutter/material/SliderThemeData-class.html

like image 160
Linar Avatar answered Sep 20 '22 08:09

Linar