animateToPage method

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

Animates the controlled PageView from the current page to the given page.

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

Implementation

Future<void> animateToPage(
  int page, {
  required Duration duration,
  required Curve curve,
}) {
  final _PagePosition position = this.position as _PagePosition;
  if (position._cachedPage != null) {
    position._cachedPage = page.toDouble();
    return Future<void>.value();
  }

  if (!position.hasViewportDimension) {
    position._pageToUseOnStartup = page.toDouble();
    return Future<void>.value();
  }

  return position.animateTo(
    position.getPixelsFromPage(page.toDouble()),
    duration: duration,
    curve: curve,
  );
}