Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index has no order #14

Open
vecharm opened this issue Aug 31, 2023 · 1 comment
Open

Index has no order #14

vecharm opened this issue Aug 31, 2023 · 1 comment

Comments

@vecharm
Copy link

vecharm commented Aug 31, 2023

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;
    }
  }
@deakjahn
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants