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
关于使用 CupertinoPageRoute,在键盘弹出时多次 rebuild 的问题研究。
参见如下资料:
https://github.com/flutter/flutter/pull/116090
https://github.com/flutter/flutter/pull/116090#issuecomment-1356014347
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
通过以上实践,我自己的项目已经能做到