getAnimations method

  1. @override
List<CharacterAnimation> getAnimations(
  1. double progress,
  2. int charCount
)
override

Produces a list of per-character animations for the given progress.

progress ranges from 0.0 (start) to 1.0 (end). The returned list must have exactly charCount elements.

Implementation

@override
List<CharacterAnimation> getAnimations(double progress, int charCount) {
  if (charCount <= 1) return List.filled(charCount, const CharacterAnimation());
  final center = (charCount - 1) / 2.0;

  return List.generate(charCount, (index) {
    final staggered = staggeredProgress(progress, index, charCount);
    final curved = applyCurve(staggered);

    // Determine direction: left (-1), right (+1), or center (0).
    final offset = index - center;
    final dir = offset < 0 ? -1.0 : (offset > 0 ? 1.0 : 0.0);
    final dx = dir * distance * (1.0 - curved);

    return CharacterAnimation(
      translation: Offset(dx, 0),
      opacity: curved.clamp(0.0, 1.0),
    );
  });
}