New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override MediaQuery for WidgetsApp #81295
Override MediaQuery for WidgetsApp #81295
Conversation
Looks like some tests are failing, can you take a look at those? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behavior should also be documented somewhere on WidgetApp
Is the |
Looked like an unrelated flake. I restarted it to see if it passes now. |
@@ -108,6 +108,9 @@ typedef InitialRouteListFactory = List<Route<dynamic>> Function(String initialRo | |||
/// It is used by both [MaterialApp] and [CupertinoApp] to implement base | |||
/// functionality for an app. | |||
/// | |||
/// If a [MediaQuery] is available above this widget a new one will not be | |||
/// created by [WidgetsApp]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document that it builds a MediaQuery with data derived from WidgetsBinding.window if no MediaQuery is available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I eventually went with:
/// If a [MediaQuery] is not available above [WidgetsApp] a [MediaQuery] is
/// built using [MediaQueryFromWindow].
because it's concise and builds a [MediaQuery] with data derived from [WidgetsBinding.window]
is already included under See also: ... *[MediaQueryFromWindow]
.
I was previously considering:
/// Builds a [MediaQuery] with data derived from [WidgetsBinding.window] if
/// [MediaQuery] is not available above [WidgetsApp]. If a [MediaQuery] is
/// available a new one will not be created by [WidgetsApp].
Let me know if you think that the second or some other variant would make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thanks for clarifying the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few documentation bits - this is a nice change!
/// [MediaQuery] using the latest [WidgetsBinding.window] values. | ||
/// | ||
/// The [MediaQuery] is wrapped in a separate widget to ensure that only it | ||
/// and its dependents are updated when `window` changes instead of rebuilding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
/// and its dependents are updated when `window` changes instead of rebuilding | |
/// and its dependents are updated when `window` changes. instead of rebuilding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean a comma here? The dot didn't make sense for me 🤔
I added a comma for now, let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, thank you. Pointed out a typo with a typo. 😋
@Piinks I updated the documentation. |
Hey @atoka93, thanks for updating. Can you rebase your branch with the latest from master? Those checks had an infra issue that has been resolved now. |
to enable reusing this functionality
so it follows the _${widgetName}State pattern
Co-authored-by: Michael Goderbauer <goderbauer@google.com>
Co-authored-by: Kate Lovett <katelovett@google.com>
That did the trick, thank you @Piinks! |
This pull request is not suitable for automatic merging in its current state.
|
@Piinks could you approve it? 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Piinks! 🚀 |
Description
Motivation described in #81293.
With these changes
WidgetsApp
will reuse an already existingMediaQuery
if there is one.It also enables moving the definition of
MediaQuery
up the tree, reusing the same logic used byWidgetsApp
in other places by makingMediaQueryFromWindow
public.Fixes #81293
Fixes #80931
Pre-launch Checklist
///
).