animateToPage method

  1. @override
Future<void> animateToPage(
  1. int page, {
  2. Duration? duration = const Duration(milliseconds: 300),
  3. Curve? curve = Curves.linear,
})
override

Animates the controlled CarouselSlider 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

@override
Future<void> animateToPage(int page, {Duration? duration = const Duration(milliseconds: 300), Curve? curve = Curves.linear}) async {
  final bool isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
  if (isNeedResetTimer) {
    _state!.onResetTimer();
  }
  final index = getRealIndex(_state!.pageController!.page!.toInt(), _state!.realPage - _state!.initialPage, _state!.itemCount);
  _setModeController();
  await _state!.pageController!.animateToPage(_state!.pageController!.page!.toInt() + page - index, duration: duration!, curve: curve!);
  if (isNeedResetTimer) {
    _state!.onResumeTimer();
  }
}