jumpToItem method
void
jumpToItem({
- required int index,
- required ScrollController scrollController,
- required double alignment,
- Rect? rect,
Immediately positions the scroll view such that the item at index is
revealed in the viewport.
The optional rect parameter describes which area of that target item
should be revealed in the viewport. If omitted, the entire item
will be revealed (subject to the constraints of the viewport).
The alignment parameter controls where the item is positioned in the
viewport. If the value is 0.0, the item will be positioned at the leading
edge of the viewport. If the value is 0.5, the item will be positioned in
the middle of the viewport. If the value is 1.0, the item will be
positioned at the trailing edge of the viewport.
Implementation
void jumpToItem({
required int index,
required ScrollController scrollController,
required double alignment,
Rect? rect,
}) {
assert(_delegate != null, "ListController is not attached.");
final offset = getOffsetToReveal(index, alignment, rect: rect);
if (offset.isFinite) {
final minExtent = scrollController.position.minScrollExtent;
final maxExtent = scrollController.position.maxScrollExtent;
final pixels = scrollController.position.pixels;
// If the scroll view is already at the edge don't do anything.
// Otherwise this may result in scrollbar handle artifacts.
if ((offset <= minExtent && pixels == minExtent) ||
(offset >= maxExtent && pixels == maxExtent)) {
return;
}
scrollController.jumpTo(offset);
} else {
_log.warning("getOffsetToReveal returned non-finite value.");
}
}