animateToPage method

Future<void> animateToPage(
  1. double page, {
  2. Curve curve = Curves.easeInOut,
  3. Duration duration = const Duration(milliseconds: 200),
  4. required TickerProvider vsync,
})

Implementation

Future<void> animateToPage(
  double page, {
  Curve curve = Curves.easeInOut,
  Duration duration = const Duration(milliseconds: 200),
  required TickerProvider vsync,
}) async {
  cancelAnimation();
  final controller =
      AnimationController(debugLabel: 'DateController', vsync: vsync);
  _animationController = controller;

  final previousPage = value.page;
  final targetPage = value.visibleRange.getTargetPageForFocus(page);
  final targetDatePageValue = DatePageValue(visibleRange, targetPage);
  controller.addListener(() {
    value = value.copyWithActivity(
      page: lerpDouble(previousPage, targetPage, controller.value)!,
      activity: controller.isAnimating
          ? DrivenDateScrollActivity(targetDatePageValue)
          : const IdleDateScrollActivity(),
    );
  });

  controller.addStatusListener((status) {
    if (status != AnimationStatus.completed) return;
    controller.dispose();
    _animationController = null;
  });

  await controller.animateTo(1, duration: duration, curve: curve);
}