init static method

void init(
  1. BuildContext context, {
  2. num width = defaultWidth,
  3. num height = defaultHeight,
  4. 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;
    _textScaler = mediaQuery.textScaler;
    _textScaleFactor = context.textScaleFactor;
  } catch (_) {
    _pixelRatio = 0;
    _screenWidth = 0;
    _screenHeight = 0;
    _statusBarHeight = 0;
    _bottomBarHeight = 0;
    _textScaleFactor = 0;
    _textScaler = null;
  }
}