init static method
void
init(
- BuildContext context, {
- num width = defaultWidth,
- num height = defaultHeight,
- bool allowFontScaling = false,
Implementation
static void init(BuildContext context,
{num width = defaultWidth,
num height = defaultHeight,
bool allowFontScaling = false}) {
_instance ??= ScreenUtil._();
_instance!.uiWidthPx = width;
_instance!.uiHeightPx = height;
_instance!.allowFontScaling = allowFontScaling;
try {
final mediaQuery = MediaQuery.of(context);
_mediaQueryData = mediaQuery;
_pixelRatio = mediaQuery.devicePixelRatio;
_screenWidth = mediaQuery.size.width;
_screenHeight = mediaQuery.size.height;
_statusBarHeight = mediaQuery.padding.top;
_bottomBarHeight = _mediaQueryData!.padding.bottom;
_textScaleFactor = mediaQuery.textScaleFactor;
} catch (_) {
_pixelRatio = 0;
_screenWidth = 0;
_screenHeight = 0;
_statusBarHeight = 0;
_bottomBarHeight = 0;
_textScaleFactor = 0;
}
}