jumpTo method
dynamic
jumpTo({})
Implementation
jumpTo(
{required T item,
bool blink = true,
bool centerItem = true,
bool onlyIfNotVisible = false}) {
if (_controller.state == null) {
return;
}
var itemIndex = _controller.state!.filteredItemsSource.indexOf(item);
if (itemIndex < 0) {
return;
}
if (onlyIfNotVisible) {
if (itemIndex > _controller.state!.firstVisibleRowIndex &&
itemIndex < _controller.state!.lastVisibleRowIndex) {
return; // The row to jump to is already visible
}
}
var itemTop = _controller.state!.rowTopCache[itemIndex];
var itemHeight = _controller.state!.settings.getRowHeight != null
? _controller.state!.settings.getRowHeight!(item)
: _controller.state!.settings.rowHeight;
var widgetHeight =
_controller.widgetState!.itemsViewScrollController.parentHeight;
double pos = -1;
if (centerItem) {
pos = itemTop - ((widgetHeight - itemHeight) / 2);
} else {
var currentPos = _controller.widgetState!.vertScrollController.offset;
var minPos = itemTop - widgetHeight + itemHeight;
var maxPos = itemTop + widgetHeight - itemHeight;
if (currentPos < minPos) {
pos = minPos;
} else if (currentPos > maxPos) {
pos = maxPos;
} else {
return; //Item is already visible
}
}
_controller.widgetState!.vertScrollController.jumpTo(pos);
//Blick the item once
if (blink) {
Timer(const Duration(milliseconds: 100), () {
_controller.state!.setMarked(item, true);
_controller.widgetState!.refresh();
Timer(const Duration(milliseconds: 500), () {
_controller.state!.setMarked(item, false);
_controller.widgetState!.refresh();
});
});
}
}