Dimibe / grouped_list

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

Bug : Header not changed once elements changed #51

Open sm2017 opened 4 years ago

sm2017 commented 4 years ago

I have a search field that filter elements, When I change elements by filtering them , sticky header (that removed by filtering) is not removed and after scrolling is removed

velval commented 3 years ago

I had the same problem and I think is got to do with below initialData state when generating the group headers.

StreamBuilder( stream: _streamController.stream, initialData: _topElementIndex, builder: (context, snapshot) => _showFixedGroupHeader(snapshot.data), ),

If you use GroupedListView within a stateful widget and your state changes (for example when changing filter elements) this _topElementIndex seemes to be pre-populated with the previous value hence showing the previous top header. It all fixes itself once you start scrolling. What I ended up doing was to create and pass the ScrollController to the GroupedListView widget and right after I changed my parent widget state I call scrollController.notifyListeners(); to manually trigger scrolling notification to re-calculate the top header group.

return GroupedListView<Point,String>( controller: _scrollController,
);

and then

setState(() { filter = newfilter; // Here is where your widget state changes _scrollController.notifyListeners(); });