ViewAppDimensContext.fromView constructor

ViewAppDimensContext.fromView(
  1. FlutterView view, {
  2. UiModeType uiModeType = UiModeType.undefined,
})

Builds a context from a raw ui.FlutterView.

Implementation

factory ViewAppDimensContext.fromView(ui.FlutterView view,
    {UiModeType uiModeType = UiModeType.undefined}) {
  final dpr = view.devicePixelRatio;
  final safeDpr = dpr.isFinite && dpr > 0 ? dpr : 1.0;
  final physical = view.physicalSize;
  final widthDp = (physical.width / safeDpr).round();
  final heightDp = (physical.height / safeDpr).round();
  final fontScale = view.platformDispatcher.textScaleFactor; // guarded below
  return ViewAppDimensContext(
    configuration: ScreenConfiguration(
      screenWidthDp: math.max(widthDp, 1),
      screenHeightDp: math.max(heightDp, 1),
      smallestScreenWidthDp: 0,
      densityDpi: (safeDpr * 160).round(),
      fontScale: fontScale,
      orientation: heightDp >= widthDp
          ? ScreenConfiguration.orientationPortrait
          : ScreenConfiguration.orientationLandscape,
    ),
    density: safeDpr,
    xdpi: safeDpr * 160,
    fontScale: fontScale.isFinite && fontScale > 0 ? fontScale : 1.0,
    uiModeType: uiModeType,
  );
}