MediaQueryData.fromView constructor

MediaQueryData.fromView(
  1. FlutterView view, {
  2. MediaQueryData? platformData,
})

Creates data for a MediaQuery based on the given view.

If provided, the platformData is used to fill in the platform-specific aspects of the newly created MediaQueryData. If platformData is null, the view's PlatformDispatcher is consulted to construct the platform-specific data.

Data which is exposed directly on the FlutterView is considered view-specific. Data which is only exposed via the FlutterView.platformDispatcher property is considered platform-specific.

Callers of this method should ensure that they also register for notifications so that the MediaQueryData can be updated when any data used to construct it changes. Notifications to consider are:

The last three notifications are only relevant if no platformData is provided. If platformData is provided, callers should ensure to call this method again when it changes to keep the constructed MediaQueryData updated.

In general, MediaQuery.of, and its associated "...Of" methods, are the appropriate way to obtain MediaQueryData from a widget. This fromView constructor is primarily for use in the implementation of the framework itself.

See also:

Implementation

MediaQueryData.fromView(ui.FlutterView view, {MediaQueryData? platformData})
  : size = view.physicalSize / view.devicePixelRatio,
    devicePixelRatio = view.devicePixelRatio,
    _textScaleFactor = 1.0, // _textScaler is the source of truth.
    _textScaler = _textScalerFromView(view, platformData),
    platformBrightness = platformData?.platformBrightness ?? view.platformDispatcher.platformBrightness,
    padding = EdgeInsets.fromViewPadding(view.padding, view.devicePixelRatio),
    viewPadding = EdgeInsets.fromViewPadding(view.viewPadding, view.devicePixelRatio),
    viewInsets = EdgeInsets.fromViewPadding(view.viewInsets, view.devicePixelRatio),
    systemGestureInsets = EdgeInsets.fromViewPadding(view.systemGestureInsets, view.devicePixelRatio),
    accessibleNavigation = platformData?.accessibleNavigation ?? view.platformDispatcher.accessibilityFeatures.accessibleNavigation,
    invertColors = platformData?.invertColors ?? view.platformDispatcher.accessibilityFeatures.invertColors,
    disableAnimations = platformData?.disableAnimations ?? view.platformDispatcher.accessibilityFeatures.disableAnimations,
    boldText = platformData?.boldText ?? view.platformDispatcher.accessibilityFeatures.boldText,
    highContrast = platformData?.highContrast ?? view.platformDispatcher.accessibilityFeatures.highContrast,
    onOffSwitchLabels = platformData?.onOffSwitchLabels ?? view.platformDispatcher.accessibilityFeatures.onOffSwitchLabels,
    alwaysUse24HourFormat = platformData?.alwaysUse24HourFormat ?? view.platformDispatcher.alwaysUse24HourFormat,
    navigationMode = platformData?.navigationMode ?? NavigationMode.traditional,
    gestureSettings = DeviceGestureSettings.fromView(view),
    displayFeatures = view.displayFeatures,
    supportsShowingSystemContextMenu = platformData?.supportsShowingSystemContextMenu ?? view.platformDispatcher.supportsShowingSystemContextMenu;