letsar / flutter_staggered_grid_view

A Flutter staggered grid view
MIT License
3.12k stars 508 forks source link

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

Open lukehutch opened 1 year ago

lukehutch commented 1 year ago

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.

lukehutch commented 1 year ago

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?

lukehutch commented 1 year ago

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.

lukehutch commented 1 year ago

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

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

but these are all workarounds...

mrtcaner commented 12 months ago

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

lukehutch commented 12 months ago

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.