Skip to content

Instantly share code, notes, and snippets.

@kirshiyin89
Created August 24, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirshiyin89/30bee44e1d2a693ccb9de8a84af7fc68 to your computer and use it in GitHub Desktop.
Save kirshiyin89/30bee44e1d2a693ccb9de8a84af7fc68 to your computer and use it in GitHub Desktop.
A utility class for the screen size.
import 'package:flutter/material.dart';
int determineCrossAxisCount(BuildContext context) {
int _crossAxisCount = 1;
final double screenWidthSize = MediaQuery.of(context).size.width;
if (screenWidthSize > 820) {
_crossAxisCount = 4;
} else if (screenWidthSize > 720) {
_crossAxisCount = 3;
} else if (screenWidthSize > 520) {
_crossAxisCount = 2;
} else {
_crossAxisCount = 1;
}
return _crossAxisCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment