Dimibe / grouped_list

A Flutter ListView in which items can be grouped into sections.
https://pub.dev/packages/grouped_list
MIT License
391 stars 107 forks source link

Wrong sticky header on first display of scrolled list #181

Closed deakjahn closed 8 months ago

deakjahn commented 1 year ago

Describe the bug When using a grouped list inside a Scrollbar and passing it a scroll controller, depending on the scroll position, it might display with some item in the middle rather than the very first item. In this situation the top sticky header isn't correct, it shows the first item's group even if we're somewhere in the middle of the list. Only the first slight movement of the list fixes it.

Expected behavior Correct sticky header upon initial display.

Information:

deakjahn commented 1 year ago

The direct cause seems to be that the StreamBuilder inside _GroupedListViewState.build() only gets fired when _scrollListener explicitely calls it (list actually scrolled and the actual item changes). I can fake the initial display if I initialize _topElementIndex to something else than zero. My immediate thought would be to actually initialize it somehow if the widget.controller is provided to the control when it's started.

I'll experiment and report back with more.

deakjahn commented 1 year ago

A quick solution. I don't PR it yet, first, it's too easy, second, I don't know whether you would think it dangerous for anything else. It looks like simply removing the condition would work:

https://github.com/Dimibe/grouped_list/blob/14143b61c7472e64ff02f4aebbb555497181b8cf/lib/grouped_list.dart#L286-L290

Just call _scrollListener() on the next frame in any case, not just for reverse.

Dimibe commented 8 months ago

Fixed with #198