Skip to content

Update MediaQuery documentation - #183702

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
nate-thegrate:MediaQuery-docs
Sep 21, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
nate-thegrate:MediaQuery-docs

Conversation

@nate-thegrate

Copy link
Copy Markdown
Contributor

This PR covers a couple of things:

  • The style guide's advice to never use "you" or "we".
  • A while back, the framework was tweaked so that 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 .maybeOf methods should be used; I'll plan on doing that if/when we decide to move forward with deprecating those methods.

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 14, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
victorsanni self-requested a review March 23, 2026 17:41
@justinmc
justinmc requested a review from dkwingsmt March 24, 2026 22:13

@victorsanni victorsanni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cleanup!

@victorsanni victorsanni added the CICD Run CI/CD label Mar 24, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 24, 2026

@dkwingsmt dkwingsmt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you teach me where runApp introduces the MediaQuery?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

void runApp(Widget app) {
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
_runWidget(binding.wrapWithDefaultView(app), binding, 'runApp');
}

runApp() calls the WidgetsBinding wrapWithDefaultView() method.


return View(
view: platformDispatcher.implicitView!,
deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: pipelineOwner,
deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: renderView,
child: rootWidget,
);

wrapWithDefaultView() returns a View widget.


@override
Widget build(BuildContext context) {
return RawView(
view: widget.view,
deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: widget._deprecatedPipelineOwner,
deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: widget._deprecatedRenderView,
child: MediaQuery.fromView(
view: widget.view,
child: FocusTraversalGroup(
policy: _policy,
child: FocusScope.withExternalFocusNode(
includeSemantics: false,
focusScopeNode: _scopeNode,
child: widget.child,
),
),
),
);
}
}

The View widget's build method returns a MediaQuery.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! I see why it is now basically impossible to have no MediaQuery in scope any more.

@dkwingsmt dkwingsmt added the CICD Run CI/CD label Mar 31, 2026
@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 31, 2026
@auto-submit

auto-submit Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

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.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 31, 2026
@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 31, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 31, 2026
@victorsanni victorsanni added the CICD Run CI/CD label Apr 2, 2026
@nate-thegrate

Copy link
Copy Markdown
Contributor Author

image

The PR has 2 approvals so I'm not sure what's going on. Maybe a rebase will fix it?

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 5, 2026
@victorsanni victorsanni added the CICD Run CI/CD label Apr 7, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 7, 2026
@auto-submit

auto-submit Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

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.

@dkwingsmt

Copy link
Copy Markdown
Contributor

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.

@dkwingsmt
dkwingsmt marked this pull request as draft April 8, 2026 20:07
@dkwingsmt dkwingsmt added the waiting for code freeze This PR is waiting for a code freeze to resolve. label Apr 8, 2026
@flutter-dashboard

Copy link
Copy Markdown

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Piinks Piinks removed the waiting for code freeze This PR is waiting for a code freeze to resolve. label Jun 24, 2026
@Piinks

Piinks commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

It looks like this PR does not affect cupertino or material so it is not blocked on the code freeze.

@nate-thegrate

Copy link
Copy Markdown
Contributor Author

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.

@Piinks

Piinks commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Greetings from stale PR triage! 👋
Is this change still on your radar?

@nate-thegrate

Copy link
Copy Markdown
Contributor Author

Thanks for the poke! I think I'm able to un-draft this one, now that #188148 has landed :)

@nate-thegrate
nate-thegrate marked this pull request as ready for review September 9, 2026 23:59
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1280 to +1281
/// For example, [MediaQuery.sizeOf] obtains the size of the current view
/// using the ancestor MediaQuery's [data].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. Documentation should be useful and provide sample code. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. 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.

MediaQuery.sizeOf signature

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. Documentation should be useful and explain the why and the how, such as when to prefer one method over another. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nate-thegrate

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants