add method

void add(
  1. P property,
  2. Animatable tween, [
  3. Duration duration = const Duration(seconds: 1),
  4. Curve curve = Curves.linear,
])

Adds a new tweening task for a specified property.

The property must relate to an enum value specified when creating the MultiTween.

Example: (using supercharged)

enum MyAniPropsEnum { width, height }

final tween = MultiTween<MyAniPropsEnum>()
  ..add(MyAniPropsEnum.width, 0.0.tweenTo(100.0), 1.seconds)
  ..add(MyAniPropsEnum.height, 0.0.tweenTo(200.0), 1.seconds);

This method also takes a Tween as the second parameter tween. Examples for tweens are Tween<double>, IntTween or ColorTween.

The third parameter is an optional duration which is by default 1 second. It's useful to arrange to animation of multiple properties. You can also get the total duration of specified duration via MultiTween.duration.

The fourth parameter is an also optional curve which is by default a linear curve. Flutter offers predefined curves inside the Curves class. Curves make your animation more interesting.

Example with curve: (using supercharged)

final tween = MultiTween<DefaultAnimationProperties>()
 ..add(DefaultAnimationProperties.width, 0.0.tweenTo(100.0), 1000.milliseconds)
 ..add(
     DefaultAnimationProperties.width, 100.0.tweenTo(200.0), 500.milliseconds, Curves.easeOut)
 ..add(DefaultAnimationProperties.height, 0.0.tweenTo(200.0), 2500.milliseconds)
 ..add(DefaultAnimationProperties.color, Colors.red.tweenTo(Colors.blue), 3.seconds,
     Curves.easeInOutSine);

Implementation

void add(P property, Animatable tween,
    [Duration duration = const Duration(seconds: 1),
    Curve curve = Curves.linear]) {
  if (!_tracks.containsKey(property)) {
    _tracks[property] = _TweenTrack();
  }

  _tracks[property]!.add(tween.chain(CurveTween(curve: curve)), duration);
}