Animatable<Color> TweenSequence throwing error in Null Safety
For some reason that I do not understand you have to make the color nullable.
Try this:
Animatable<Color> animColorPend = TweenSequence([
TweenSequenceItem(
weight: 1.0,
tween: ColorTween(
begin: Colors.purple,
end: Colors.white,
) as Animatable<Color?>,
),
TweenSequenceItem(
weight: 1.0,
tween: ColorTween(
begin: Colors.white,
end: Colors.purple,
) as Animatable<Color?>,
),
]);
oupoup
Updated on December 01, 2022Comments
-
oupoup over 1 year
I just migrated my flutter app in Null Safety. Everything seems to be working well, except the below code:
Animatable<Color> animColorPend = TweenSequence<Color>([ TweenSequenceItem( weight: 1.0, tween: ColorTween( begin: Colors.purple, end: Colors.white, ) as Animatable<Color>, ), TweenSequenceItem( weight: 1.0, tween: ColorTween( begin: Colors.white, end: Colors.purple, ) as Animatable<Color>, ), ]);
The cast (as Animatable) is throwing this error:
type 'ColorTween' is not a subtype of type 'Animatable' in type cast
Previously (and when I run the app with --no-sound-null-safety) I didn't get this error. Could that be a bug coming from something not yet implemented, as it says here (https://flutter.dev/docs/null-safety)
Not all parts of the Flutter SDK support null safety yet, as some parts still need additional work to migrate to null safety.
Or do you think there is something in the code? Everything I tried (removing the cast, initializing a TweenSequence and not the abstract class and so on) will not work. Thanks for the help!
-
CatOverflow about 3 yearsDoes this answer your question? flutter dart error dart(argument_type_not_assignable)
-
oupoup about 3 yearsYes indeed! This one is what I used and solved the issue. Apparently there is sth going on with Animatable... Thank you very much
-