首页 > 解决方案 > 无论设备方向如何,如何在颤动中获取屏幕尺寸

问题描述

无论设备方向如何,如何使屏幕高度颤动?据我所知,媒体查询的高度随设备方向而变化。

标签: flutter

解决方案


您可以检查方向是横向还是纵向:

Orientation currentOrientation = MediaQuery.of(context).orientation;
if(currentOrientation == Orientation.portrait){
    height = MediaQuery.of(context).size.height
} else {
   height = MediaQuery.of(context).size.width
 }

推荐阅读