letsar / flutter_staggered_grid_view

A Flutter staggered grid view

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`crossAxisCellCount` and `mainAxisCellCount` are reversed?

lukehutch opened this issue · comments

Using StaggeredGridTile.count, if I specify

              crossAxisCellCount: 1,
              mainAxisCellCount: 2,

then I get cells that are twice as tall as they are wide, whereas if I specify

              crossAxisCellCount: 2,
              mainAxisCellCount: 1,

then I get cells that are twice as wide as they are tall.

This seems reversed, since layout is left-to-right, then top-to-bottom -- so the main axis is the horizontal axis.

It depends on the axis direction of the scroll. If the scroll is horizontal, then the mainAxisCellCount refers to the number of cells in the horizontal axis whereas if the scroll if vertical, then, mainAxisCellCount refers to the number of cells in the vertical axis.

For the example I gave, the scroll direction was vertical.

It does not seem reversed to me, if the scroll is vertical and you want a cell that occupies 2 cells in the main axis and 1 cell in the cross axis then you'll get something like the blue cell in the image below.
If you want a cell which occupies 2 cells in the cross axis and 1 cell in the main one, you'll get the green one.
cell

Not sure how I kept managing to reverse this in my head. Sorry to take your time on this!

@lukehutch It seems I'm late but I'm writing this for those who will struggle this issue like me. StaggeredGrid.count behaves differently depending on it's parent. When you use it directly, mainAxis will be horizontal line. But if you wrap it with ListView your mainAxis will be vertical line. In readme example it's mainAxis is vertical line and crossAxis is horizontal line. So if you wrap your StaggeredGrid with ListView (which has Axis.vertical scroll direction) it will behave as specified in the readme example.