Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add height and width aspects to MediaQuery. #167828

Closed
@ksokolovskyi

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)

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