handleTrackTapDown method

  1. @protected
  2. @mustCallSuper
void handleTrackTapDown(
  1. TapDownDetails details
)

Handler called when the track is tapped in order to page in the tapped direction.

Implementation

@protected
@mustCallSuper
void handleTrackTapDown(TapDownDetails details) {
  // The Scrollbar should page towards the position of the tap on the track.
  assert(_debugCheckHasValidScrollPosition());
  _cachedController = _effectiveScrollController;

  final ScrollPosition position = _cachedController!.position;
  if (!position.physics.shouldAcceptUserOffset(position)) {
    return;
  }

  // Determines the scroll direction.
  final AxisDirection scrollDirection;

  switch (axisDirectionToAxis(position.axisDirection)) {
    case Axis.vertical:
      if (details.localPosition.dy > scrollbarPainter._thumbOffset) {
        scrollDirection = AxisDirection.down;
      } else {
        scrollDirection = AxisDirection.up;
      }
    case Axis.horizontal:
      if (details.localPosition.dx > scrollbarPainter._thumbOffset) {
        scrollDirection = AxisDirection.right;
      } else {
        scrollDirection = AxisDirection.left;
      }
  }

  final ScrollableState? state = Scrollable.maybeOf(position.context.notificationContext!);
  final ScrollIntent intent = ScrollIntent(direction: scrollDirection, type: ScrollIncrementType.page);
  assert(state != null);
  final double scrollIncrement = ScrollAction.getDirectionalIncrement(state!, intent);

  _cachedController!.position.moveTo(
    _cachedController!.position.pixels + scrollIncrement,
    duration: const Duration(milliseconds: 100),
    curve: Curves.easeInOut,
  );
}