更新Flutter之后的绘画问题

时间:2020-08-07 17:14:38

标签: flutter dart

今天,当我更新Flutter时,我的paint方法开始出现错误,以前从未引起任何问题:

@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,
  }) {

这是错误:

error: 'CustomSlider.paint' ('void Function(PaintingContext, Offset, {Animation<double> activationAnimation, Animation<double> enableAnimation, bool isDiscrete, TextPainter labelPainter, RenderBox parentBox, SliderThemeData sliderTheme, TextDirection textDirection, double value})')
isn't a valid override of 'SliderComponentShape.paint' ('void Function(PaintingContext, Offset, {Animation<double> activationAnimation, Animation<double> enableAnimation, bool isDiscrete, TextPainter labelPainter, RenderBox parentBox, Size sizeWithOverflow, SliderThemeData sliderTheme, TextDirection textDirection, double textScaleFactor, double value})'). 
(invalid_override at [app_name] lib/Home/path_to_file:20)

1 个答案:

答案 0 :(得分:3)

现在看来,您现在需要在替代项中指定sizeWithOverflow:https://api.flutter.dev/flutter/material/SliderComponentShape/paint.html 我对该领域不熟悉,但是在Github代码中似乎有对该参数的描述:

https://github.com/flutter/flutter/blob/2ae34518b8/packages/flutter/lib/src/material/slider_theme.dart#L1006

因此您需要将以上内容更改为:

@override
void paint(
    PaintingContext context,
    Offset center, {
    Animation<double> activationAnimation,
    Animation<double> enableAnimation,
    bool isDiscrete,
    TextPainter labelPainter,
    RenderBox parentBox,
    Size sizeWithOverflow, /*The missing link*/
    double textScaleFactor, /*And the missing link I missed*/
    SliderThemeData sliderTheme,
    TextDirection textDirection,
    double value,
  }) {

希望有帮助。

P.S。我建议将来使用文本比较工具来更轻松地解决此类问题。我喜欢使用BeyondCompare,但就是我。