Paint issue after updating Flutter

123*_*765 2 dart flutter

Today when I updated Flutter I began to get an error with my paint method which had never caused any problems before:

@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,
  }) {
Run Code Online (Sandbox Code Playgroud)

This is the error:

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)
Run Code Online (Sandbox Code Playgroud)

Nic*_*uer 6

看起来您现在需要在覆盖中指定 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,
  }) {
Run Code Online (Sandbox Code Playgroud)

希望有帮助。

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