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

推荐使用 useInheritedMediaQuery 为 false #485

Merged
merged 1 commit into from
May 31, 2023
Merged

推荐使用 useInheritedMediaQuery 为 false #485

merged 1 commit into from
May 31, 2023

Conversation

naivetoby
Copy link
Contributor

关于使用 CupertinoPageRoute,在键盘弹出时多次 rebuild 的问题研究。

参见如下资料:

flutter/flutter#116090

flutter/flutter#116090 (comment)

  • If we did want to avoid rebuilding when MediaQuery changes. We can use MediaQueryData.fromWindow(window) to get value, and using didChangeMetrics to update value and call setState() when it is current page, which will not break current theory and will works fine too.

  • Set Scaffold's resizeToAvoidBottomInset to false when you don't need adjust viewInsets, because when resizeToAvoidBottomInset is true, the Scaffold will use MediaQuery.viewInsetsOf to subscribe the changes and rebuild when it changes. So set it to false when this page doesn't need to adjust viewInsets.

  • Using Builder to avoid rebuild all things in a page

通过以上实践,我自己的项目已经能做到

  • 不监听 MediaQuery 且 resizeToAvoidBottomInset 为 false 键盘弹出不会 rebuild。
  • 监听 MediaQuery 或者 resizeToAvoidBottomInset 为 true,在 CupertinoPageRoute 中的页面会 rebuild,但不掉帧。
  • (未验证,我认为没有必要) 如果在监听 MediaQuery 或者 resizeToAvoidBottomInset 为 true 的情况下,连 CupertinoPageRoute 都不想 rebuild,似乎可以将 https://api.flutter.dev/flutter/material/MaterialPageRoute/maintainState.html 设置为false。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants