staggerInterval static method

Interval staggerInterval(
  1. int index,
  2. int totalItems, {
  3. double overlapRatio = 0.5,
})

Calculates stagger interval for use with AnimationController.

index - The item's position totalItems - Total number of items overlapRatio - How much animations overlap (0.0-1.0)

Implementation

static Interval staggerInterval(
  int index,
  int totalItems, {
  double overlapRatio = 0.5,
}) {
  if (totalItems <= 1) return const Interval(0.0, 1.0);

  final segmentLength = 1.0 / totalItems;
  final overlap = segmentLength * overlapRatio;

  final start = (index * segmentLength * (1 - overlapRatio)).clamp(0.0, 1.0);
  final end = (start + segmentLength + overlap).clamp(0.0, 1.0);

  return Interval(start, end, curve: smooth);
}