我在颤振中使用 Slider 类。我想改变滑块的拇指形状,为此我正在创建一个下面的类。一切都很好,但重写“paint()”方法是在类下面抛出错误。请参阅下面的代码并尽可能提供任何解决方案。
class CustomSliderThumbRect extends SliderComponentShape {
final double thumbRadius;
final thumbHeight;
final int min;
final int max;
const CustomSliderThumbRect({
this.thumbRadius,
this.thumbHeight,
this.min,
this.max,
});
@override
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
return Size.fromRadius(thumbRadius);
}
@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,
double textScaleFactor,
Size sizeWithOverflow,
})
{
final Canvas canvas = context.canvas;
final rRect = RRect.fromRectAndRadius(
Rect.fromCenter(
center: center, width: thumbHeight * 1.2, height: thumbHeight * .6),
Radius.circular(thumbRadius * .4),
);
final paint = Paint()
..color = sliderTheme.activeTrackColor //Thumb Background Color
..style = PaintingStyle.fill;
TextSpan span = new TextSpan(
style: new TextStyle(
fontSize: thumbHeight * .3,
fontWeight: FontWeight.w700,
color: sliderTheme.thumbColor,
height: 1),
text: '${getValue(value)}');
TextPainter tp = new TextPainter(
text: span,
textAlign: TextAlign.left,
// textDirection: TextDirection.ltr
// textDirection: ui.TextDirection.ltr,
);
tp.layout();
Offset textCenter =
Offset(center.dx - (tp.width / 2), center.dy - (tp.height / 2));
canvas.drawRRect(rRect, paint);
tp.paint(canvas, textCenter);
}
String getValue(double value) {
return (min+(max-min)*value).round().toString();
}
}
错误
方法“CustomSliderThumbRect.paint”的参数“textDirection”的类型为“TextDirection/ 1 /”,与覆盖方法“SliderComponentShape.paint”中的相应类型“TextDirection/ 2 /”不匹配。
- 'TextDirection/ 1 /' 来自'package:intl/intl.dart' ('../../../Tools/flutter/.pub-cache/hosted/pub.dartlang.org/intl-0.15.8 /lib/intl.dart')。
- “TextDirection/ 2 /”来自“dart:ui”。更改为“TextDirection/ 2 /”的超类型,或者,对于协变参数,更改为子类型。文本方向文本方向,