Search code examples
flutterstaggered-gridview

Flutter: wrong itemBuilder index order in StaggeredGridView


So, I passed the padding of the StaggeredGridView element manually, checking the index in the itemBuilder method, but there is a wrong index order. Starting from the 3rd index, the order is different, and after some scrolling there will be indices with other order.

enter image description here

Indexes:

enter image description here

After some scroll:

enter image description here

I can't use padding and axis spaces of staggered grid view for avoid leading and trailing white spaces of top horizontal categories list view. How to solve that a problem?

Thanks in advance!


Solution

  • Assuming you are using the flutter_staggered_grid_view package. Staggered grid view doesn't order items from left to right and then vertically. Within a "row" of items, the one further up than the other will be first in order of indexes.

    Check out the package documentation. There's a pretty self explanatory image there.