indicatorScrollToIndex method

  1. @override
void indicatorScrollToIndex(
  1. int index,
  2. List<Size>? sizeList,
  3. Duration duration,
  4. TickerProvider vsync,
  5. ValueNotifier<IndicatorPosition> notifier,
)
override

Implementation

@override
void indicatorScrollToIndex(
    int index,
    List<Size>? sizeList,
    Duration duration,
    TickerProvider vsync,
    ValueNotifier<IndicatorPosition> notifier) {
  double left = notifier.value.left;

  double targetLeft =
      controller.getTargetItemScrollEndOffset(sizeList, index).dx -
          (sizeList![index].width + width) / 2;

  _animationController =
      AnimationController(duration: duration, vsync: vsync);

  _animation =
      Tween(begin: left, end: targetLeft).animate(_animationController!);
  _animation.addListener(() {
    double right =
        controller.getTabBarSize(sizeList).width - _animation.value - width;

    notifier.value = IndicatorPosition(_animation.value, right, 0, 0);
    controller.forEachListenerCallback();
  });

  _animationController!.forward();
}