飞镖错误飞镖(argument_type_not_assignable) [英] flutter dart error dart(argument_type_not_assignable)

查看:252
本文介绍了飞镖错误飞镖(argument_type_not_assignable)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下对AnimationController的驱动器功能的调用会导致错误消息:

The following call to the drive function of the AnimationController leads to the error message:

不能将参数类型'ColorTween'分配给参数类型'Animatable'

The argument type 'ColorTween' can't be assigned to the parameter type 'Animatable'

Animation<Color> animation = animationController.drive(ColorTween(begin: Colors.red, end: colors.blue));

但是ColorTween是Tween< Color?>.Tween< T扩展了动态范围.是可动画的T.如何解决此错误?是个 '?'在颜色或动态"之后一个问题?显式强制转换也不起作用:

Yet ColorTween is a Tween<Color?> and Tween<T extends dynamic> is an Animatable<T>. How can I fix this error? Is the '?' after Color or 'dynamic' a problem? Explicit casting didn't work either:

类型'ColorTween'不是类型'Animatable< Color>'的子类型强制转换

type 'ColorTween' is not a subtype of type 'Animatable<Color>' in type cast

flutter 2.0.4 dart 2.12.2

推荐答案

赋值中 Animation Color 类型缺少'?'因为 ColorTween Tween< Color?> .

The Color type of the Animation in the assignment is missing the '?' as ColorTween is a Tween<Color?>.

这篇关于飞镖错误飞镖(argument_type_not_assignable)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆