Hi, sorry for the delay.
The difficulty if you wanted to implement it in the custom object example is that you should be able to implement *, + and - for the Color class which is not trivial (it probably doesn’t make sense).
For complex objects like Color, there are custom Tween classes like ColorTween in this case.
Just like this class, you can create a custom Tween in order to animate your properties.
Here is a modified version of the FadeAway class that includes a Color:
class FadeAway {
final Offset offset;
final double opacity;
final Color color;
const FadeAway(
this.offset,
this.opacity,
this.color,
);
}
Now, create a new class that extends Tween and override the lerp method:
class MyCustomTween extends Tween<FadeAway> {
MyCustomTween({
required FadeAway begin,
required FadeAway end,
}) : super(begin: begin, end: end);
@override
FadeAway lerp(double t) {
if (begin == null || end == null) {
// Handle begin or end null, here just throw
throw "Cannot lerp between $begin and $end";
}
return FadeAway(
Offset.lerp(begin!.offset, end!.offset, t)!,
lerpDouble(begin!.opacity, end!.opacity, t)!,
Color.lerp(begin!.color, end!.color, t)!,
);
}
}
Now you can use that Tween for your animations:
MyCustomTween specialTween = MyCustomTween(
begin: FadeAway(Offset.zero, 0.0, Colors.blue),
end: FadeAway(Offset(100, 100), 1.0, Colors.red),
);
Hope it helps!