huge_listview
huge_listview copied to clipboard
Index has no order
When the page is very long, three pages, four pages or more, after scrolling and then scrolling back to the first page, listener.itemPositions.value is no longer in order, scrollable_positioned_list is not sorted, so listener.itemPositions.value.first is not guaranteed to be The first visible content. This must be done after sorting
int _currentFirst() {
try {
var itemPositions = listener.itemPositions.value.toList(growable: false)
..sort((a, b) => a.index - b.index);
return itemPositions.first.index;
} catch (e) {
return 0;
}
}
First, I'd really like to see some way to reproduce this problem first. :-) Second, if it's really so, judging from the code, a sort looks like overkill to me. Isn't this just a 'find the minimum' operation? That would be cheaper, just a single iteration, no need to convert to list and sort. Maybe something like
return listener.itemPositions.value.reduce(min).index;
but without being able to reproduce it in the first place, I can't test it...