ScreenScaleProperties constructor

ScreenScaleProperties({
  1. double? width,
  2. double? height,
  3. bool? allowFontScaling,
  4. bool? allowSubpixel,
  5. double? maxWidth,
})

Implementation

factory ScreenScaleProperties({
  double? width,
  double? height,
  bool? allowFontScaling,
  bool? allowSubpixel,
  double? maxWidth,
}) {
  if (maxWidth == null &&
      width == null &&
      height == null &&
      allowFontScaling == null) {
    return ScreenScale;
  }
  final pixelRatio = WidgetsBinding.instance!.window.devicePixelRatio;
  final physicalWidth = WidgetsBinding.instance!.window.physicalSize.width;
  var widthCalc = maxWidth != null
      ? math.min(maxWidth * pixelRatio, physicalWidth)
      : physicalWidth;
  return _instance = ScreenScaleProperties._(
    uiWidthPx: width ??
        WidgetsBinding.instance!.window.physicalSize.width / pixelRatio,
    uiHeightPx: height ??
        (WidgetsBinding.instance!.window.physicalSize.height / pixelRatio),
    allowFontScaling: allowFontScaling ?? false,
    allowSubpixel: allowSubpixel ?? allowFontScaling ?? false,
    pixelRatio: WidgetsBinding.instance!.window.devicePixelRatio,
    screenWidth: widthCalc,
    screenHeight: WidgetsBinding.instance!.window.physicalSize.height,
    statusBarHeight: WidgetsBinding.instance!.window.padding.top,
    bottomBarHeight: WidgetsBinding.instance!.window.padding.bottom,
    textScaleFactor: WidgetsBinding.instance!.window.textScaleFactor,
  );
}