You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: shrink the MediaQuery API surface #183701
MediaQuery's maybeOf methods are unneccessary; I propose we deprecate and remove them to make the API docs easier to read.
(We could also deprecate the obsolete debugCheckHasMediaQuery function.)
This mitigates time wasted by developers, since there won't be a need to ask "do I use sizeOf or maybeSizeOf?"
are they? Flutter does support widget trees without a MediaQuery (RawView, widgets above View in multi-view runWidget apps, and wrapWithView: false tests, etc).
Also won't this break (public) optionally depending on a single MediaQuery property? Unless we expose _MediaQueryAspect which I don't see why we should do?
Overall this seems like way too much churn (even with the dart fix) for a proposal that doesn't seem a pressing community demand. Basically a classic Breaking changes that would improve the overall API proposal.
Overall this seems like way too much churn (even with the dart fix) for a proposal that doesn't seem a pressing community demand.
To be honest I 100% agree. I was fairly disappointed with how complicated #194091 was: when compared to the convenience of a smaller API surface it doesn't really feel worth it.
I'll also go ahead and voice my opinion on a few areas of disagreement:
Flutter does support widget trees without a MediaQuery (RawView, widgets above View in multi-view runWidget apps, and wrapWithView: false tests, etc).
You're correct to say this, but I still think that MediaQuery's maybeOf methods are unneccessary: just because it's technically possible for a context to lack a MediaQuery answer doesn't mean that it's realistically possible. The View widget automatically builds a MediaQuery; in order to create a scenario without one, a developer would have to use runWidget instead of runApp and ignore the advice from the runWidget docs: "It is up to the caller to include at least one View widget… RenderObjectWidgets without an ancestor View widget will result in an exception."
Also won't this break (public) optionally depending on a single MediaQuery property?
Based on my definition of "optionally depending on a single property", it's not possible to do it with the existing API. If there's a MediaQuery in scope (which is all but guaranteed), a method like maybeSizeOf or maybePaddingOf will always create a dependency.
Activity
nate-thegrate commentedon Mar 14, 2026
Exceptions would be:
These methods refer to nullable MediaQueryData properties, so even with a MediaQuery in the widget tree they can still return null.
Oddly, there's both a displayCornerRadiiOf and a maybeDisplayCornerRadiiOf method for the nullable displayCornerRadii property. I imagine we may want to get rid of one of them, but I don't have a strong opinion about it.
Update `MediaQuery` documentation (flutter#183702)
victorsanni commentedon Nov 10, 2026
are they? Flutter does support widget trees without a
MediaQuery(RawView, widgets aboveViewin multi-viewrunWidgetapps, andwrapWithView: falsetests, etc).Also won't this break (public) optionally depending on a single
MediaQueryproperty? Unless we expose_MediaQueryAspectwhich I don't see why we should do?Overall this seems like way too much churn (even with the
dart fix) for a proposal that doesn't seem a pressing community demand. Basically a classic Breaking changes that would improve the overall API proposal.nate-thegrate commentedon Nov 10, 2026
To be honest I 100% agree. I was fairly disappointed with how complicated #194091 was: when compared to the convenience of a smaller API surface it doesn't really feel worth it.
I'll also go ahead and voice my opinion on a few areas of disagreement:
You're correct to say this, but I still think that MediaQuery's
maybeOfmethods are unneccessary: just because it's technically possible for a context to lack a MediaQuery answer doesn't mean that it's realistically possible. The View widget automatically builds aMediaQuery; in order to create a scenario without one, a developer would have to userunWidgetinstead ofrunAppand ignore the advice from the runWidget docs: "It is up to the caller to include at least oneViewwidget…RenderObjectWidgets without an ancestorViewwidget will result in an exception."Based on my definition of "optionally depending on a single property", it's not possible to do it with the existing API. If there's a MediaQuery in scope (which is all but guaranteed), a method like
maybeSizeOformaybePaddingOfwill always create a dependency.I think it'd be worth revisiting Breaking changes that would improve the overall API proposal, since much of what's listed there was written prior to when data-driven fixes were introduced.
But for now I think it makes sense to close this issue and the linked PR. Thanks for looking into this and sharing your feedback.