animateToItem method

Future<void> animateToItem(
  1. int itemIndex, {
  2. required Duration duration,
  3. required Curve curve,
})

Animates the controlled scroll view to the given item index.

The animation lasts for the given duration and follows the given curve. The returned Future resolves when the animation completes.

The duration and curve arguments must not be null.

Implementation

Future<void> animateToItem(
  int itemIndex, {
  required Duration duration,
  required Curve curve,
}) async {
  if (!hasClients) {
    return;
  }

  final List<Future<void>> futures = <Future<void>>[];
  for (_FixedExtentScrollPosition position in positions as List<dynamic>) {
    futures.add(position.animateTo(
      itemIndex * position.itemExtent,
      duration: duration,
      curve: curve,
    ));
  }
  await Future.wait<void>(futures);
}