flutter - 更新 Flutter 后的绘制问题
问题描述
今天,当我更新 Flutter 时,我的绘制方法开始出现错误,以前从未引起任何问题:
@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)
解决方案
看起来您现在需要在覆盖中指定 sizeWithOverflow:https ://api.flutter.dev/flutter/material/SliderComponentShape/paint.html 我不熟悉该字段,但似乎有一个描述Github 代码中的那个参数:
因此,您需要将上述内容更改为:
@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,
}) {
希望有帮助。
PS 我建议将来使用文本比较工具来更轻松地解决此类问题。我喜欢使用 BeyondCompare,但这就是我。
推荐阅读
- typescript - 打字稿`可以用不同的约束子类型实例化`错误
- c++ - 如何使用 SDL_audio 生成音调?
- vue.js - 从子路由导航到父路由,不会重新挂载父路由
- javascript - 家长当我点击它时隐藏
- elasticsearch - 匹配与通配符查询之间的区别
- php-7.4 - 升级到 PHP-7.4,小数分隔符问题
- python - python:逐行打印多个字典和字符串
- c++ - 类对象是否可以保留指向自身的静态指针?
- flutter - 如何从 Flutter 的 Locale 类中获取常量列表?
- android - 如何使用视图绑定从 Fragment 更改父活动中的视图