animateCSSSequence function

Future<void>? animateCSSSequence(
  1. Iterable<CSSAnimationConfig> animationsConfig, {
  2. Duration? initialDelay,
  3. int? repeat,
  4. bool? repeatInfinity,
})

Sames animateCSS but runs animationsConfig in sequence;

Implementation

Future<void>? animateCSSSequence(Iterable<CSSAnimationConfig> animationsConfig,
    {Duration? initialDelay, int? repeat, bool? repeatInfinity}) {
  var animationsList = animationsConfig.where((e) => e.isValid).toList();
  if (animationsList.isEmpty) return null;

  if (animationsList.length == 1) {
    return animationsList[0].play(initialDelay: initialDelay);
  }

  repeat ??= 0;
  repeatInfinity ??= false;

  if (initialDelay != null && initialDelay.inMilliseconds > 0) {
    return Future.delayed(initialDelay, () {
      return _animateCSSSequenceRepeat(animationsList, repeat!, repeatInfinity);
    });
  } else {
    return _animateCSSSequenceRepeat(animationsList, repeat, repeatInfinity);
  }
}