letsar / flutter_staggered_grid_view

A Flutter staggered grid view

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`StaggeredGrid` does not support any aspect ratio other than 1:1

lukehutch opened this issue · comments

StaggeredGrid uses square grid cells (which can be combined into rectangles, but those rectangles are still multiples of the base square on each axis). I want to make a StaggeredGrid, but with cells that have a 9:16 aspect ratio. I can't see a way to do this, and the other grid types don't support the type of layouts that StaggeredGrid does.

Actually for this usecase, I guess I can just multiply the number of columns in the grid by 9, and the number of rows by 16, and fill a 9x16-multiple area of the grid with each tile, but I imagine that will be inefficient for the layout algorithm?

However even with that solution, the sizes of the cells are not quite right, because I want the usable cell size to have the aspect ratio 9:16, but the size is calculated based on the cell size plus crossAxisSpacing / mainAxisSpacing, which slightly changes the aspect ratio.

... and it looks like there's a fix to that too, to use:

          mainAxisSpacing: gridSpacing,
          crossAxisSpacing: gridSpacing * 9 / 16,

but these are all workarounds...

Have you tried using "StaggeredGridTile.fit"? You can create custom size tiles thus precise custom aspect ratios

I haven't -- I ended up using a different layout solution.

However, the .fit constructor is not documented, which is why I didn't discover it -- this needs to be added to the documentation.