flutter dart error dart(argument_type_not_assignable)

Issue

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

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));

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:

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

flutter 2.0.4
dart 2.12.2

Solution

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

Answered By – Objective

Answer Checked By – Dawn Plyler (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.