Dimibe / grouped_list

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

Define a specific order list for the groups #142

Closed rivella50 closed 2 years ago

rivella50 commented 2 years ago

Hi there, let's say i have list items and know that they can only have a discrete number of possible state values (e.g. 'new', 'inbox', 'planned') which should serve as our groups. Now i have to render groups in a specific order which cannot be established by comparing the group names, i.e. the option using groupComparator falls away. Is there a way that this can be achieved currently with grouped_list, where neither a comparator nor natural sort order would be correct? If not how about a new option (e.g. 'specificGroupOrder'), where the user can overrule all sorting algorithms and provide the group names in the order he actually needs in the rendered view?

Thanks for considering my request.

Dimibe commented 2 years ago

You can actually use use the groupComperator for this. Inside you can compare the static state values and hard code the order of the states. I think this is the solution you are thinking of.

A more flexible solution would be to have a order mapped to each state so that the ordering itself does not have to be hard coded in the groupComparator.

rivella50 commented 2 years ago

Works fine, thanks a lot.