Visitar URL original
Update `MediaQuery` documentation to highlight asynchronous nature of size by gspencergoog · Pull Request #135719 · flutter/flutter · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions packages/flutter/lib/src/cupertino/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,9 @@ class CupertinoDynamicColor extends Color with Diagnosticable {

/// Resolves this [CupertinoDynamicColor] using the provided [BuildContext].
///
/// Calling this method will create a new [CupertinoDynamicColor] that is almost
/// identical to this [CupertinoDynamicColor], except the effective color is
/// changed to adapt to the given [BuildContext].
/// Calling this method will create a new [CupertinoDynamicColor] that is
/// almost identical to this [CupertinoDynamicColor], except the effective
/// color is changed to adapt to the given [BuildContext].
///
/// For example, if the given [BuildContext] indicates the widgets in the
/// subtree should be displayed in dark mode (the surrounding
Expand All @@ -1000,17 +1000,18 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
/// except its effective color will be the `darkHighContrastElevatedColor`
/// variant from the original [CupertinoDynamicColor].
///
/// Calling this function may create dependencies on the closest instance of some
/// [InheritedWidget]s that enclose the given [BuildContext]. E.g., if [darkColor]
/// is different from [color], this method will call [CupertinoTheme.of], and
/// then [MediaQuery.of] if brightness wasn't specified in the theme data retrieved
/// from the previous [CupertinoTheme.of] call, in an effort to determine the
/// brightness value.
///
/// If any of the required dependencies are missing from the given context, the
/// default value of that trait will be used ([Brightness.light] platform
/// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base] elevation
/// level).
/// Calling this function may create dependencies on the closest instance of
/// some [InheritedWidget]s that enclose the given [BuildContext]. E.g., if
/// [darkColor] is different from [color], this method will call
/// [CupertinoTheme.maybeBrightnessOf] in an effort to determine the
/// brightness. If [color] is different from [highContrastColor], this method
/// will call [MediaQuery.maybeHighContrastOf] in an effort to determine the
/// high contrast setting.
///
/// If any of the required dependencies are missing from the given context,
/// the default value of that trait will be used ([Brightness.light] platform
/// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base]
/// elevation level).
CupertinoDynamicColor resolveFrom(BuildContext context) {
Brightness brightness = Brightness.light;
if (_isPlatformBrightnessDependent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class BottomNavigationBar extends StatefulWidget {
/// bottom navigation bar defaults for an entire application.
/// * [BottomNavigationBarTheme] - which can be used to specify
/// bottom navigation bar defaults for a widget subtree.
/// * [MediaQuery.of] - which can be used to determine the current
/// * [MediaQuery.orientationOf] - which can be used to determine the current
/// orientation.
final BottomNavigationBarLandscapeLayout? landscapeLayout;

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/painting/edge_insets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class EdgeInsets extends EdgeInsetsGeometry {
/// Creates insets that match the given view padding.
///
/// If you need the current system padding or view insets in the context of a
/// widget, consider using [MediaQuery.of] to obtain these values rather than
/// widget, consider using [MediaQuery.paddingOf] to obtain these values rather than
/// using the value from a [FlutterView] directly, so that you get notified of
/// changes.
EdgeInsets.fromViewPadding(ui.ViewPadding padding, double devicePixelRatio)
Expand Down
11 changes: 1 addition & 10 deletions packages/flutter/lib/src/rendering/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// changes.
///
/// {@tool snippet}
/// Querying [MediaQuery] directly. Preferred.
/// Querying [MediaQuery.platformBrightnessOf] directly. Preferred.
///
/// ```dart
/// final Brightness brightness = MediaQuery.platformBrightnessOf(context);
Expand All @@ -400,15 +400,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// ```
/// {@end-tool}
///
/// {@tool snippet}
/// Querying [MediaQueryData].
///
/// ```dart
/// final MediaQueryData mediaQueryData = MediaQuery.of(context);
/// final Brightness brightness = mediaQueryData.platformBrightness;
/// ```
/// {@end-tool}
///
/// See [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged].
@protected
void handlePlatformBrightnessChanged() { }
Expand Down
11 changes: 8 additions & 3 deletions packages/flutter/lib/src/widgets/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ abstract mixin class WidgetsBindingObserver {
///
/// See also:
///
/// * [MediaQuery.of], which provides a similar service with less
/// * [MediaQuery.sizeOf], which provides a similar service with less
/// boilerplate.
void didChangeMetrics() { }

Expand Down Expand Up @@ -229,14 +229,19 @@ abstract mixin class WidgetsBindingObserver {
///
/// See also:
///
/// * [MediaQuery.of], which provides a similar service with less
/// * [MediaQuery.textScaleFactorOf], which provides a similar service with less
/// boilerplate.
void didChangeTextScaleFactor() { }

/// Called when the platform brightness changes.
///
/// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged].
///
/// See also:
///
/// * [MediaQuery.platformBrightnessOf], which provides a similar service with
/// less boilerplate.
void didChangePlatformBrightness() { }

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