jumpToHeader method

void jumpToHeader(
  1. int index,
  2. Axis axis
)

Jumps the scroll position of an axis from its current value to the corresponding value of a header in the index index.

See also:

Implementation

void jumpToHeader(int index, Axis axis) {
  if (!isAttached) {
    return;
  }

  final scrollController = getScrollControllerFor(axis: axis)!;

  // Get the pixel offset of this header necessary to make it visible.
  final jumpOffset = _getOffsetToHeader(index, axis, scrollController);

  // If there is no jump offset, don't scroll
  if (jumpOffset == null) {
    return;
  }

  // Finally, apply offset
  scrollController.jumpTo(jumpOffset);
}