animateTo method

  1. @override
DecorationPainter animateTo(
  1. DecorationPainter endValue,
  2. double t
)
override

Animate to next decoration state, each decoration should implement this. This is just regular lerp function, but instead of static function where you pass start and end state, here we start with current state and animate to endValue.

Implementation

@override
DecorationPainter animateTo(DecorationPainter endValue, double t) {
  if (endValue is WidgetDecoration) {
    return WidgetDecoration(
      widgetDecorationBuilder: t > 0.5
          ? endValue.widgetDecorationBuilder
          : widgetDecorationBuilder,
      margin: EdgeInsets.lerp(margin, endValue.margin, t) ?? endValue.margin,
    );
  }

  return this;
}