Skip to content

Commit c68fd6a

Browse files
authored
Add troubleshooting doc for MediaQueryData.size (#104828)
1 parent 64b08f3 commit c68fd6a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ class MediaQueryData {
159159
/// pixels are the size of the actual hardware pixels on the device. The
160160
/// number of physical pixels per logical pixel is described by the
161161
/// [devicePixelRatio].
162+
///
163+
/// ## Troubleshooting
164+
///
165+
/// It is considered bad practice to cache and later use the size returned
166+
/// by `MediaQuery.of(context).size`. It will make the application non responsive
167+
/// and might lead to unexpected behaviors.
168+
/// For instance, during startup, especially in release mode, the first returned
169+
/// size might be (0,0). The size will be updated when the native platform
170+
/// reports the actual resolution.
171+
///
172+
/// See the article on [Creating responsive and adaptive
173+
/// apps](https://docs.flutter.dev/development/ui/layout/adaptive-responsive)
174+
/// for an introduction.
175+
///
176+
/// See also:
177+
///
178+
/// * [FlutterView.physicalSize], which returns the size in physical pixels.
162179
final Size size;
163180

164181
/// The number of device pixels for each logical pixel. This number might not

0 commit comments

Comments
 (0)