-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[defunct] MediaQuery as InheritedModel #97928
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
Conversation
dadf6d6 to
1a2f307
Compare
1a2f307 to
2cadd44
Compare
2cadd44 to
33f72d7
Compare
|
Gold has detected about 1 new digest(s) on patchset 2. |
|
Is this still being worked on? |
|
I think I need to make an issue so that it will be reviewed. Will do that. |
ea50c52 to
66bc46a
Compare
|
I propose a more universal solution: Since it will be useful not only for |
|
Can anyone here review the PR? This improves the performance of many apps. |
|
This looks very promising 👍🏻 Thanks for your work. |
|
Hi, This can be very useful for my application as I am facing a lot of jank on soft keyboard pop-up. However, I am relatively new to Flutter programming. Can someone please guide me how I can use @moffatman's solution? As in how do I pull his github into my Flutter code? |
|
Can anyone here review this? This is not a breaking change and for all who modify their code a lot of unnecessary rebuilds will be avoided... @Piinks |
|
any update on this? still not in stable? |
|
I thought of some default values here. But the more I think about it, I would rather not add new default values, and just keep the minimum compatibility the old behaviour. I don't see the value of hiding this likely accidental state where there is no
|
packages/flutter/test/cupertino/text_selection_toolbar_test.dart
Outdated
Show resolved
Hide resolved
I agree with this. |
goderbauer
left a comment
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.
LGTM
@gspencergoog FYI since you're currently working on unifying the ofs and maybeOfs.
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 wonder if it makes sense for size to be something where you can depend on just the width or just the height changing? I think most properties it doesn't make sense to go down another level like that, but size is something that can have huge redraw implications, and if we can avoid rebuilding a widget when the height changes and the widget only cares about width (like in a horizontal widget during keyboard animation), that could be good.
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.
There was a discussion about this above and we decided against exposing sub-properties for now.
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.
You could possible have like 18 more methods including topPaddingOf, leftViewInsetsOf... I see the value but let's hold on that for now.
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.
Ahh, OK. I missed that discussion.
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
@moffatman Sorry for the hassle, but could you close this PR and open a new one with the same change? It looks like since this PR is so old our golden testing infra got confused by it and is in a corrupted state. Opening this as a new PR should resolve the issue. |
When some aspect of the flutter
MediaQuerychanges, every widget which depends onMediaQuery.of(context)is rebuilt. Most of these rebuilds are unnecessary, since most changes toMediaQuerydo not change more than 1 or 2 fields at a time (window resizing, system brightness changing, system font scale changing).MediaQuery does not change often on mobile, but resizing desktop windows happens often and flutter should be able to handle being resized without dropping frames. There is one place that MediaQuery is rapidly updated on mobile: on iOS, as the keyboard opens,
MediaQueryis updated every frame with the only change being the keyboard insets.Here is a demo program, resizing the window causes
MyHomePageto rebuild needlessly. The issue here could be alleviated by better Widget encapsulation, but many framework widgets are rebuilt on every change inMediaQuerywhen they depend on rarely-changing properties such asplatformBrightnessortextScaleFactor.This change makes
MediaQueryanInheritedModelrather than anInheritedWidget, so any widget which knows it only depends on a specific property ofMediaQuerythe ability to declare that when reading theMediaQueryfrom the context.For example,
could become
as a performance optimization.
MediaQuery.of(context)will continue to work as it always has.Fixes #102060
Pre-launch Checklist
///).