getScreenSize static method
Get the current screen size category
Implementation
static ScreenSize getScreenSize(BuildContext context) {
if (_screenSize != null && _screenSizeData == MediaQuery.of(context).size) {
return _screenSize!;
}
final size = MediaQuery.of(context).size;
final width = size.width;
final height = size.height;
final isPortrait = height > width;
// Update cached values
_screenSizeData = size;
// Determine screen size based on width and orientation
if (isPortrait) {
if (width < 480) {
_screenSize = ScreenSize.xs;
} else if (width < 768) {
_screenSize = ScreenSize.sm;
} else if (width < 1024) {
_screenSize = ScreenSize.md;
} else if (width < 1440) {
_screenSize = ScreenSize.lg;
} else {
_screenSize = ScreenSize.xl;
}
} else {
// Landscape orientation
if (width < 768) {
_screenSize = ScreenSize.xs;
} else if (width < 1024) {
_screenSize = ScreenSize.sm;
} else if (width < 1440) {
_screenSize = ScreenSize.md;
} else if (width < 1920) {
_screenSize = ScreenSize.lg;
} else {
_screenSize = ScreenSize.xl;
}
}
return _screenSize!;
}