animateFromTo method

Future<void> animateFromTo({
  1. int fromIndex = 0,
  2. required int toIndex,
  3. Duration delayDuration = const Duration(milliseconds: 500),
  4. bool isReverse = false,
})

Implementation

Future<void> animateFromTo({
  int fromIndex = 0,
  required int toIndex,
  Duration delayDuration = const Duration(milliseconds: 500),
  bool isReverse = false,
}) async {
  for (var i = fromIndex;
      (!isReverse) ? i < toIndex : i > toIndex;
      (isReverse) ? i-- : i++) {
    await Future.delayed(delayDuration);
    if (isReverse) {
      if (i < 0) {
        continue;
      } else if (i > length) {
        return;
      }
    } else {
      if (i > length) {
        return;
      }
    }
    animateTo(
      i,
    );
  }
  return;
}