Skip to content

Add height and width aspects to MediaQuery. #167828

Closed

Description

@ksokolovskyi

Use case

In many places in Flutter apps, we only need one screen dimension (height or width). To get it we have to call MediaQuery.sizeOf(context).height or MediaQuery.sizeOf(context).width. This causes the widget to rebuild whenever any property of the size changes, even if we only care about one dimension. That's not ideal.

After checking the Flutter repo, I noticed that 14 out of 28 calls to sizeOf use just one dimension. So this seems like a fairly common pattern.

Proposal

I'd like to propose adding four static functions to MediaQuery:

MediaQuery.widthOf(context)
MediaQuery.maybeWidthOf(context)
MediaQuery.heightOf(context)
MediaQuery.maybeHeightOf(context)

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Apr 28, 2025
  2. github-actions commented on May 20, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  3. locked as resolved and limited conversation to collaborators on May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions