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 curved = applyCurve(progress);

  return List.generate(charCount, (index) {
    double dx;
    if (fromCenter) {
      // Spread outward symmetrically from the center character.
      final center = (charCount - 1) / 2.0;
      final offset = index - center;
      dx = offset * spacing * curved;
    } else {
      // Spread rightward from the first character.
      dx = index * spacing * curved / (charCount - 1);
    }
    return CharacterAnimation(translation: Offset(dx, 0));
  });
}