Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 77d8ec0

Browse files
authored
Add more points to [MediaQuery]. (#43649)
See flutter/flutter#11697
1 parent c5841c5 commit 77d8ec0

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

lib/ui/window.dart

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ class FlutterView {
126126
/// The Flutter framework operates in logical pixels, so it is rarely
127127
/// necessary to directly deal with this property.
128128
///
129-
/// When this changes, [PlatformDispatcher.onMetricsChanged] is called.
129+
/// When this changes, [PlatformDispatcher.onMetricsChanged] is called. When
130+
/// using the Flutter framework, using [MediaQuery.of] to obtain the device
131+
/// pixel ratio (via [MediaQueryData.devicePixelRatio]), instead of directly
132+
/// obtaining the [devicePixelRatio] from a [FlutterView], will automatically
133+
/// cause any widgets dependent on this value to rebuild when it changes,
134+
/// without having to listen to [PlatformDispatcher.onMetricsChanged].
130135
///
131136
/// See also:
132137
///
@@ -158,7 +163,12 @@ class FlutterView {
158163
/// The dimensions of the rectangle into which the scene rendered in this view
159164
/// will be drawn on the screen, in physical pixels.
160165
///
161-
/// When this changes, [PlatformDispatcher.onMetricsChanged] is called.
166+
/// When this changes, [PlatformDispatcher.onMetricsChanged] is called. When
167+
/// using the Flutter framework, using [MediaQuery.of] to obtain the size (via
168+
/// [MediaQueryData.size]), instead of directly obtaining the [physicalSize]
169+
/// from a [FlutterView], will automatically cause any widgets dependent on the
170+
/// size to rebuild when the size changes, without having to listen to
171+
/// [PlatformDispatcher.onMetricsChanged].
162172
///
163173
/// At startup, the size of the view may not be known before Dart code runs.
164174
/// If this value is observed early in the application lifecycle, it may
@@ -182,7 +192,12 @@ class FlutterView {
182192
/// which the view can render, but over which the operating system will likely
183193
/// place system UI, such as the keyboard, that fully obscures any content.
184194
///
185-
/// When this property changes, [PlatformDispatcher.onMetricsChanged] is called.
195+
/// When this property changes, [PlatformDispatcher.onMetricsChanged] is
196+
/// called. When using the Flutter framework, using [MediaQuery.of] to obtain
197+
/// the insets (via [MediaQueryData.viewInsets]), instead of directly
198+
/// obtaining the [viewInsets] from a [FlutterView], will automatically cause
199+
/// any widgets dependent on the insets to rebuild when they change, without
200+
/// having to listen to [PlatformDispatcher.onMetricsChanged].
186201
///
187202
/// The relationship between this [viewInsets],
188203
/// [viewPadding], and [padding] are described in
@@ -208,7 +223,12 @@ class FlutterView {
208223
/// change in response to the soft keyboard being visible or hidden, whereas
209224
/// [padding] will.
210225
///
211-
/// When this property changes, [PlatformDispatcher.onMetricsChanged] is called.
226+
/// When this property changes, [PlatformDispatcher.onMetricsChanged] is
227+
/// called. When using the Flutter framework, using [MediaQuery.of] to obtain
228+
/// the padding (via [MediaQueryData.viewPadding]), instead of directly
229+
/// obtaining the [viewPadding] from a [FlutterView], will automatically cause
230+
/// any widgets dependent on the padding to rebuild when it changes, without
231+
/// having to listen to [PlatformDispatcher.onMetricsChanged].
212232
///
213233
/// The relationship between this [viewInsets],
214234
/// [viewPadding], and [padding] are described in
@@ -254,7 +274,12 @@ class FlutterView {
254274
/// not drawn (to account for the bottom soft button area), but will be `0.0`
255275
/// when the soft keyboard is visible.
256276
///
257-
/// When this changes, [PlatformDispatcher.onMetricsChanged] is called.
277+
/// When this changes, [PlatformDispatcher.onMetricsChanged] is called. When
278+
/// using the Flutter framework, using [MediaQuery.of] to obtain the padding
279+
/// (via [MediaQueryData.padding]), instead of directly obtaining the
280+
/// [padding] from a [FlutterView], will automatically cause any widgets
281+
/// dependent on the padding to rebuild when it changes, without having to
282+
/// listen to [PlatformDispatcher.onMetricsChanged].
258283
///
259284
/// The relationship between this [viewInsets], [viewPadding], and [padding]
260285
/// are described in more detail in the documentation for [FlutterView].
@@ -389,6 +414,11 @@ class SingletonFlutterWindow extends FlutterView {
389414
///
390415
/// {@macro dart.ui.window.accessorForwardWarning}
391416
///
417+
/// When using the Flutter framework, the [MediaQuery] widget exposes much of
418+
/// these metrics. Using [MediaQuery.of] to obtain them allows the framework
419+
/// to automatically rebuild widgets that depend on them, without having to
420+
/// manage the [onMetricsChanged] callback.
421+
///
392422
/// See [PlatformDispatcher.onMetricsChanged] for more information.
393423
VoidCallback? get onMetricsChanged => platformDispatcher.onMetricsChanged;
394424
set onMetricsChanged(VoidCallback? callback) {
@@ -400,11 +430,11 @@ class SingletonFlutterWindow extends FlutterView {
400430
/// {@template dart.ui.window.accessorForwardWarning}
401431
/// Accessing this value returns the value contained in the
402432
/// [PlatformDispatcher] singleton, so instead of getting it from here, you
403-
/// should consider getting it from `WidgetsBinding.instance.platformDispatcher` instead
404-
/// (or, when `WidgetsBinding` isn't available, from
405-
/// [PlatformDispatcher.instance]). The reason this value forwards to the
406-
/// [PlatformDispatcher] is to provide convenience for applications that only
407-
/// use a single main window.
433+
/// should consider getting it from
434+
/// `WidgetsBinding.instance.platformDispatcher` instead (or, when
435+
/// `WidgetsBinding` isn't available, from [PlatformDispatcher.instance]). The
436+
/// reason this value forwards to the [PlatformDispatcher] is to provide
437+
/// convenience for applications that only use a single main window.
408438
/// {@endtemplate}
409439
///
410440
/// This establishes the language and formatting conventions that window

0 commit comments

Comments
 (0)