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

Sticky header not updated on web #202

Open matteoberla opened 4 months ago

matteoberla commented 4 months ago

Describe the bug When scrolling down using the mouse and then returning back to the top of the list, the sticky header is not updated correctly and it remains stack to another header. I've noticed that it only happens when the height of the items grouped under an header is lower that a certain amout. (Not sure of the following) This amount seems to be connected to the "step" that the view make each time the mouse wheel is scrolled as it doesn't move row by row, instead it seems to skip some rows.

If i use the lateral bar the problem is not happening, probably because the scroll action is made step by step. The bug is UI only.

List at startup list ok

List after scrolling up and down (you see that the first item Ven, 08/03/2024 is repeated two times through the list) list bug

Expected behavior I don't know if it's possibile fix this issue as it strictly depends on the mouse that a user is using, but updating the header to the correct one would be nice.

Information:

matteoberla commented 4 months ago

find a solution in the initstate on the widget

@override
  void initState() {
    _controller = widget.controller ?? ScrollController();
    if (widget.useStickyGroupSeparators) {
      _controller.addListener(() {
        WidgetsBinding.instance.addPostFrameCallback((_) {
          _scrollListener();
        });
      });
    }
    super.initState();
  }

As the _scrollListener was not receiving the updated data after a scroll action i've added WidgetsBinding.instance.addPostFrameCallback so it waits until the frame is complete and then take the y, max and topElementIndex.

Please add this to fix the issue in the web platform. I've also tried on mobile and nothing changed, still working perfecty!