gpt4 book ai didi

Flutter - 删除 Slider 中的默认填充

转载 作者:行者123 更新时间:2023-12-04 12:07:50 30 4
gpt4 key购买 nike

我想知道如何删除 Flutter Slider 中的默认填充
当前输出是这样的,默认填充滑块清晰可见
enter image description here
这是我的代码::

                    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);
},
)
)
),
),
)

最佳答案

您可以使用自定义 trackShape 修复它,如下所示:
将此行添加到 SliderTheme 数据:

trackShape: CustomTrackShape(),
然后在 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);}}
enter image description here

关于Flutter - 删除 Slider 中的默认填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65661119/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com