我正在尝试为颤振滑块实现自定义进度指示器。至于现在,我有绘制指标的给定代码。
class InsideSliderValueIndicator extends SliderComponentShape {
@override
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
return Size.zero;
}
@override
void paint(
PaintingContext context,
Offset center, {
Animation<double> activationAnimation,
Animation<double> enableAnimation,
bool isDiscrete,
TextPainter labelPainter,
RenderBox parentBox,
SliderThemeData sliderTheme,
TextDirection textDirection,
double value,
}) {
final sliderWidth = parentBox.size.width;
final sliderBoxOffset = parentBox.localToGlobal(Offset.zero);
labelPainter.paint(
context.canvas,
Offset(sliderBoxOffset.dx + sliderWidth / 2 - labelPainter.width / 2,
center.dy - labelPainter.height / 2));
}
}
我还自定义了滑块以移除拇指。这是它的样子:
这段代码的问题是它sliderBoxOffset
不返回“滑块”的框,而是返回父卡的框,center
实际上是滑块上拇指相对于父卡的位置。
所以我的问题是:如何从给定的参数中获得滑块的中心?
谢谢您的帮助