Skip to content
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

Merged
merged 17 commits into from Jun 23, 2021
Merged

Override MediaQuery for WidgetsApp #81295

merged 17 commits into from Jun 23, 2021

Conversation

atoka93
Copy link
Contributor

@atoka93 atoka93 commented Apr 27, 2021

Description

Motivation described in #81293.

With these changes WidgetsApp will reuse an already existing MediaQuery if there is one.
It also enables moving the definition of MediaQuery up the tree, reusing the same logic used by WidgetsApp in other places by making MediaQueryFromWindow public.

Fixes #81293
Fixes #80931

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Apr 27, 2021
@google-cla google-cla bot added the cla: yes label Apr 27, 2021
@atoka93 atoka93 changed the title Override mediaquery Override MediaQuery for WidgetsApp Apr 27, 2021
@goderbauer
Copy link
Member

Looks like some tests are failing, can you take a look at those?

Copy link
Member

@goderbauer goderbauer left a 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

packages/flutter/lib/src/widgets/app.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/app.dart Outdated Show resolved Hide resolved
@atoka93
Copy link
Contributor Author

atoka93 commented Apr 29, 2021

Is the Linux framework_tests_libraries failing caused by the changes?

@atoka93 atoka93 requested a review from goderbauer April 29, 2021 08:39
@goderbauer
Copy link
Member

Is the Linux framework_tests_libraries failing caused by the changes?

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].
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

packages/flutter/lib/src/widgets/app.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/app.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/app.dart Outdated Show resolved Hide resolved
@flutter-dashboard flutter-dashboard bot added the f: material design flutter/packages/flutter/material repository. label May 6, 2021
@atoka93 atoka93 requested a review from goderbauer May 6, 2021 10:36
@atoka93 atoka93 requested a review from Hixie June 9, 2021 22:41
@Piinks Piinks added a: quality A truly polished experience c: new feature Nothing broken; request for a new capability labels Jun 10, 2021
Copy link
Contributor

@Piinks Piinks left a 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!

packages/flutter/lib/src/widgets/media_query.dart Outdated Show resolved Hide resolved
/// [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
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
/// and its dependents are updated when `window` changes instead of rebuilding
/// and its dependents are updated when `window` changes. instead of rebuilding

Copy link
Contributor Author

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

Copy link
Contributor

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. 😋

packages/flutter/lib/src/widgets/app.dart Outdated Show resolved Hide resolved
@atoka93
Copy link
Contributor Author

atoka93 commented Jun 21, 2021

@Piinks I updated the documentation.
Some checks were cancelled and I don't seem to be able to find a way to re-trigger them.

@atoka93 atoka93 requested a review from Piinks June 22, 2021 18:36
@Piinks
Copy link
Contributor

Piinks commented Jun 22, 2021

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.

atoka93 and others added 5 commits June 23, 2021 06:50
Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: Kate Lovett <katelovett@google.com>
@atoka93
Copy link
Contributor Author

atoka93 commented Jun 23, 2021

That did the trick, thank you @Piinks!

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • Please get at least one approved review before re-applying this label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@atoka93
Copy link
Contributor Author

atoka93 commented Jun 23, 2021

@Piinks could you approve it? 🙏

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Flutter_LGTM

@atoka93
Copy link
Contributor Author

atoka93 commented Jun 23, 2021

Thank you @Piinks! 🚀

renyou added a commit that referenced this pull request Jun 24, 2021
renyou added a commit that referenced this pull request Jun 24, 2021
@zs-dima
Copy link

zs-dima commented Jul 20, 2021

@Piinks @atoka93
Why this changes had been reverted back ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: quality A truly polished experience c: new feature Nothing broken; request for a new capability f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
6 participants