[英]Flutter - Remove default padding in Slider
I am wondering how I can remove the default padding in Flutter Slider
我想知道如何删除Flutter Slider
中的默认填充
Current output is like this, default padding of Slider is clearly visible当前的output是这样的,Slider的默认padding清晰可见
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);
},
)
)
),
),
)
you can fix it with costum trackShape like this:您可以像这样使用 costum trackShape 修复它:
add this line to SliderTheme data:将此行添加到 SliderTheme 数据:
trackShape: CustomTrackShape(),
then inside CustomTrackShape() you must write this code:然后在 CustomTrackShape() 中,您必须编写以下代码:
class CustomTrackShape extends RoundedRectSliderTrackShape {Rect getPreferredRect({
@required RenderBox parentBox,
Offset offset = Offset.zero,
@required SliderThemeData sliderTheme,
bool isEnabled = false,
bool isDiscrete = false,}) {final double trackHeight = sliderTheme.trackHeight;
final double trackLeft = offset.dx;
final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2;
final double trackWidth = parentBox.size.width;
return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);}}
SliderThemeData(overlayShape: SliderComponentShape.noOverlay)
or或者
overlayShape: SliderComponentShape.noThumb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.