getCrossAxisCount static method

int getCrossAxisCount(
  1. double width
)

Determines the appropriate cross-axis count based on screen width.

  • Width < 600px: Returns 1 (list view)
  • 600px ≤ Width < 1024px: Returns 2 (2-column grid)
  • Width ≥ 1024px: Returns 3 (3+ column grid)

You can override this with a custom gridDelegate if needed.

Implementation

static int getCrossAxisCount(double width) {
  if (width >= tablet) {
    return 3;
  }
  if (width >= mobile) {
    return 2;
  }
  return 1;
}