更新Flutter后的绘制问题

brjng4g3  于 2023-05-29  发布在  Flutter
关注(0)|答案(2)|浏览(135)

今天当我更新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)
u91tlkcl

u91tlkcl1#

看起来你现在需要在你的覆盖中指定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,但这就是我。

ldioqlga

ldioqlga2#

如果你的课碰巧是这样的,

class YourClass extends SliderTrackShape
with BaseSliderTrackShape

你遇到这个错误,你最喜欢的一个参数是

Offset? secondaryOffset

整个结构应该是这样的

@override
  void paint(
    PaintingContext context,
    Offset offset, {
    @required RenderBox? parentBox,
    @required SliderThemeData? sliderTheme,
    @required Animation<double>? enableAnimation,
    @required TextDirection? textDirection,
    @required Offset? thumbCenter,
    bool isDiscrete = false,
    bool isEnabled = false,
    double additionalActiveTrackHeight = 2,
    Offset? secondaryOffset,
  })

相关问题