huge_listview icon indicating copy to clipboard operation
huge_listview copied to clipboard

Index has no order

Open vecharm opened this issue 1 year ago • 1 comments

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;
    }
  }

vecharm avatar Aug 31 '23 04:08 vecharm

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...

deakjahn avatar Sep 12 '23 10:09 deakjahn