Repository navigation
Update MediaQuery documentation - #183702
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the documentation for MediaQuery and MediaQueryData. The changes primarily involve rephrasing documentation comments to remove personal pronouns like 'you' and 'we' and to use passive voice, aligning with the repository's style guide. Additionally, the documentation for MediaQuery is updated to correctly state that the runApp function, rather than WidgetsApp or MaterialApp, is responsible for introducing and updating the MediaQuery.
victorsanni
left a comment
There was a problem hiding this comment.
LGTM, thanks for the cleanup!
dkwingsmt
left a comment
There was a problem hiding this comment.
Generally LGTM except for one question.
| /// See also: | ||
| /// | ||
| /// * [WidgetsApp] and [MaterialApp], which introduce a [MediaQuery] and keep | ||
| /// * The [runApp] function, which introduces a [MediaQuery] and keeps |
There was a problem hiding this comment.
Can you teach me where runApp introduces the MediaQuery?
There was a problem hiding this comment.
Sure!
flutter/packages/flutter/lib/src/widgets/binding.dart
Lines 1874 to 1877 in aaa24c3
runApp() calls the WidgetsBinding wrapWithDefaultView() method.
flutter/packages/flutter/lib/src/widgets/binding.dart
Lines 1635 to 1640 in aaa24c3
wrapWithDefaultView() returns a View widget.
flutter/packages/flutter/lib/src/widgets/view.dart
Lines 269 to 288 in aaa24c3
The View widget's build method returns a MediaQuery.
There was a problem hiding this comment.
Thank you very much! I see why it is now basically impossible to have no MediaQuery in scope any more.
|
autosubmit label was removed for flutter/flutter/183702, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
53d619e to
605535b
Compare
|
autosubmit label was removed for flutter/flutter/183702, because - The status or check suite Mac_arm64 tool_tests_commands has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Thanks for your contribution! This PR has reached completion, however we're not able to merge this PR for the moment due to the Material/Cupertino code freeze (#184093). As soon as the decoupling is complete, we will post a way to port this PR to the new packages to land. In the meantime, I'll convert this PR to a draft and apply a label so that we can quickly find it when the freeze is lifted. |
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
It looks like this PR does not affect cupertino or material so it is not blocked on the code freeze. |
|
Thank you, that was my thought as well! I suppose we're good to un-draft and land this change, aside from needing to respect the limit of 2 concurrent open PRs. |
|
Greetings from stale PR triage! 👋 |
|
Thanks for the poke! I think I'm able to un-draft this one, now that #188148 has landed :) |
393ad83 to
58acc26
Compare
There was a problem hiding this comment.
Code Review
This pull request updates the documentation in media_query.dart to rephrase sentences, removing direct references to "you" or "your app" and improving clarity. The review feedback suggests retaining the concrete code example for MediaQuery.sizeOf and the guidance on when to prefer MediaQuery.maybeOf over MediaQuery.of, while still adhering to the style changes.
| /// For example, [MediaQuery.sizeOf] obtains the size of the current view | ||
| /// using the ancestor MediaQuery's [data]. |
There was a problem hiding this comment.
By removing the concrete code example and the reference to [FlutterView], the documentation becomes less helpful for developers trying to understand how to use MediaQuery.sizeOf. We can rephrase the original text to avoid using "you" or "your app" while still keeping the useful code example and context.
/// For example, [MediaQuery.sizeOf] can be used to obtain the size of the
/// current view (e.g., the [FlutterView] containing the app):
/// MediaQuery.sizeOf(context).References
- Documentation should be useful and provide sample code. (link)
There was a problem hiding this comment.
I like this documentation as-is, since it provides useful advice while avoiding unnecessary redundancy.
I removed the reference to FlutterView for a couple of reasons:
- FlutterView is a class that developers usually don't need to interact with directly, whereas MediaQuery is used all the time, so I didn't feel that the reference was worth it.
- The "e.g." parenthetical didn't make much sense here, since the FlutterView is always the source of truth for the view size.
Dart's function signatures are self-documenting, to some degree. In the case of MediaQuery.sizeOf, the fact that the method takes a BuildContext is obvious.
My guess is that the original reason for the MediaQuery.sizeOf(context) snippet is that in the English language, putting "of" at the end of a sentence feels weird, so the contributor felt like they needed to add something there.
| /// Use this function if you want to allow situations where no [MediaQuery] is | ||
| /// in scope. Prefer using [MediaQuery.of] in situations where a media query | ||
| /// is always expected to exist. | ||
| /// Returns `null` if no [MediaQuery] is in scope. |
There was a problem hiding this comment.
The original documentation contained useful guidance on when to prefer MediaQuery.maybeOf versus MediaQuery.of. Completely removing this guidance makes the documentation less helpful. We can rephrase the guidance to avoid using "you" while keeping the valuable recommendation.
/// This is appropriate when a [MediaQuery] might not be in scope. If a
/// [MediaQuery] is expected to always be present, [MediaQuery.of] is preferred.
///
/// Returns null if no [MediaQuery] is in scope.References
- Documentation should be useful and explain the why and the how, such as when to prefer one method over another. (link)
There was a problem hiding this comment.
I feel pretty strongly that the simple "Returns null if no [MediaQuery] is in scope" is fine here, due to the precedent set by documentation for other .maybeOf() methods and the fact that there isn't a realistic scenario where no MediaQuery is in scope.
|
I believe we're ready to land this PR. I'll do a rebase to mitigate any potential CI issues, also feel free to read through Gemini's review and let me know if anything should be changed from here. |
58acc26 to
a585487
Compare

This PR covers a couple of things:
runApp()creates and updates the MediaQuery instead of MaterialApp or WidgetsApp. The MediaQuery docs have yet to be updated with this information.This PR is related to #183701, but I haven't added any recommendations regarding whether or not
.maybeOfmethods should be used; I'll plan on doing that if/when we decide to move forward with deprecating those methods.