7

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

Objective
  • 848
  • 1
  • 12
  • 27
  • 1
    @pskink The assignment was the problem after all. It needs to be Animation as ColorTween is a Tween. The error message is a bit misleading. – Objective Apr 10 '21 at 18:03
  • yes indeed, it is misleading... imho they should be more specific that `null safety` is the problem, not the base type (`Animatiable`) – pskink Apr 11 '21 at 02:46

2 Answers2

12

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

Objective
  • 848
  • 1
  • 12
  • 27
3

Try like this:

TweenSequenceItem(
  weight: 1.0,
  tween: ColorTween(
    begin: Colors.black,
    end: Colors.lightBlue,
  ) as Animatable<Color>,
)
IvanPavliuk
  • 1,460
  • 1
  • 21
  • 16