Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5e3e78

Browse files
authored
Update MediaQuery documentation to highlight asynchronous nature of size (#135719)
## Description This updates the documentation for `MediaQuery` and `Overlay` to include the following: - That `MediaQueryData.size` is set asynchronously, and doesn't necessarily reflect the size of the current frame. - That the specific `MediaQuery.sizeOf` and related methods are preferred over the more generic `MediaQuery.of`. - That the size of the `Overlay` isn't necessarily the size returned by `MediaQueryData.size` As well as adding some symbol links, and fixing some error in documentation. ## Tests - Documentation only
1 parent ff73448 commit a5e3e78

8 files changed

Lines changed: 335 additions & 206 deletions

File tree

packages/flutter/lib/src/cupertino/colors.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,9 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
984984

985985
/// Resolves this [CupertinoDynamicColor] using the provided [BuildContext].
986986
///
987-
/// Calling this method will create a new [CupertinoDynamicColor] that is almost
988-
/// identical to this [CupertinoDynamicColor], except the effective color is
989-
/// changed to adapt to the given [BuildContext].
987+
/// Calling this method will create a new [CupertinoDynamicColor] that is
988+
/// almost identical to this [CupertinoDynamicColor], except the effective
989+
/// color is changed to adapt to the given [BuildContext].
990990
///
991991
/// For example, if the given [BuildContext] indicates the widgets in the
992992
/// subtree should be displayed in dark mode (the surrounding
@@ -1000,17 +1000,18 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
10001000
/// except its effective color will be the `darkHighContrastElevatedColor`
10011001
/// variant from the original [CupertinoDynamicColor].
10021002
///
1003-
/// Calling this function may create dependencies on the closest instance of some
1004-
/// [InheritedWidget]s that enclose the given [BuildContext]. E.g., if [darkColor]
1005-
/// is different from [color], this method will call [CupertinoTheme.of], and
1006-
/// then [MediaQuery.of] if brightness wasn't specified in the theme data retrieved
1007-
/// from the previous [CupertinoTheme.of] call, in an effort to determine the
1008-
/// brightness value.
1009-
///
1010-
/// If any of the required dependencies are missing from the given context, the
1011-
/// default value of that trait will be used ([Brightness.light] platform
1012-
/// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base] elevation
1013-
/// level).
1003+
/// Calling this function may create dependencies on the closest instance of
1004+
/// some [InheritedWidget]s that enclose the given [BuildContext]. E.g., if
1005+
/// [darkColor] is different from [color], this method will call
1006+
/// [CupertinoTheme.maybeBrightnessOf] in an effort to determine the
1007+
/// brightness. If [color] is different from [highContrastColor], this method
1008+
/// will call [MediaQuery.maybeHighContrastOf] in an effort to determine the
1009+
/// high contrast setting.
1010+
///
1011+
/// If any of the required dependencies are missing from the given context,
1012+
/// the default value of that trait will be used ([Brightness.light] platform
1013+
/// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base]
1014+
/// elevation level).
10141015
CupertinoDynamicColor resolveFrom(BuildContext context) {
10151016
Brightness brightness = Brightness.light;
10161017
if (_isPlatformBrightnessDependent) {

packages/flutter/lib/src/material/bottom_navigation_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class BottomNavigationBar extends StatefulWidget {
426426
/// bottom navigation bar defaults for an entire application.
427427
/// * [BottomNavigationBarTheme] - which can be used to specify
428428
/// bottom navigation bar defaults for a widget subtree.
429-
/// * [MediaQuery.of] - which can be used to determine the current
429+
/// * [MediaQuery.orientationOf] - which can be used to determine the current
430430
/// orientation.
431431
final BottomNavigationBarLandscapeLayout? landscapeLayout;
432432

packages/flutter/lib/src/painting/edge_insets.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class EdgeInsets extends EdgeInsetsGeometry {
400400
/// Creates insets that match the given view padding.
401401
///
402402
/// If you need the current system padding or view insets in the context of a
403-
/// widget, consider using [MediaQuery.of] to obtain these values rather than
403+
/// widget, consider using [MediaQuery.paddingOf] to obtain these values rather than
404404
/// using the value from a [FlutterView] directly, so that you get notified of
405405
/// changes.
406406
EdgeInsets.fromViewPadding(ui.ViewPadding padding, double devicePixelRatio)

packages/flutter/lib/src/rendering/binding.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
385385
/// changes.
386386
///
387387
/// {@tool snippet}
388-
/// Querying [MediaQuery] directly. Preferred.
388+
/// Querying [MediaQuery.platformBrightnessOf] directly. Preferred.
389389
///
390390
/// ```dart
391391
/// final Brightness brightness = MediaQuery.platformBrightnessOf(context);
@@ -400,15 +400,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
400400
/// ```
401401
/// {@end-tool}
402402
///
403-
/// {@tool snippet}
404-
/// Querying [MediaQueryData].
405-
///
406-
/// ```dart
407-
/// final MediaQueryData mediaQueryData = MediaQuery.of(context);
408-
/// final Brightness brightness = mediaQueryData.platformBrightness;
409-
/// ```
410-
/// {@end-tool}
411-
///
412403
/// See [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged].
413404
@protected
414405
void handlePlatformBrightnessChanged() { }

packages/flutter/lib/src/widgets/binding.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ abstract mixin class WidgetsBindingObserver {
176176
///
177177
/// See also:
178178
///
179-
/// * [MediaQuery.of], which provides a similar service with less
179+
/// * [MediaQuery.sizeOf], which provides a similar service with less
180180
/// boilerplate.
181181
void didChangeMetrics() { }
182182

@@ -229,14 +229,19 @@ abstract mixin class WidgetsBindingObserver {
229229
///
230230
/// See also:
231231
///
232-
/// * [MediaQuery.of], which provides a similar service with less
232+
/// * [MediaQuery.textScaleFactorOf], which provides a similar service with less
233233
/// boilerplate.
234234
void didChangeTextScaleFactor() { }
235235

236236
/// Called when the platform brightness changes.
237237
///
238238
/// This method exposes notifications from
239239
/// [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged].
240+
///
241+
/// See also:
242+
///
243+
/// * [MediaQuery.platformBrightnessOf], which provides a similar service with
244+
/// less boilerplate.
240245
void didChangePlatformBrightness() { }
241246

242247
/// Called when the system tells the app that the user's locale has
@@ -589,7 +594,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
589594
/// For example, the [WidgetsApp] widget registers as a binding
590595
/// observer and passes the screen size to a [MediaQuery] widget
591596
/// each time it is built, which enables other widgets to use the
592-
/// [MediaQuery.of] static method and (implicitly) the
597+
/// [MediaQuery.sizeOf] static method and (implicitly) the
593598
/// [InheritedWidget] mechanism to be notified whenever the screen
594599
/// size changes (e.g. whenever the screen rotates).
595600
///

0 commit comments

Comments
 (0)