flutter - 无论设备方向如何,如何在颤动中获取屏幕尺寸
问题描述
无论设备方向如何,如何使屏幕高度颤动?据我所知,媒体查询的高度随设备方向而变化。
解决方案
您可以检查方向是横向还是纵向:
Orientation currentOrientation = MediaQuery.of(context).orientation;
if(currentOrientation == Orientation.portrait){
height = MediaQuery.of(context).size.height
} else {
height = MediaQuery.of(context).size.width
}
推荐阅读
- r - 如何计算期望值和方差,然后在 R 中从这个分布中模拟 500 个样本
- c - cuda 内核没有访问数组的所有元素
- javascript - 为什么我从 c# 到 js 得到不同的 MD5 哈希?
- node.js - 如何使节点需要来自 node_modules 的 es5 lib
- android - 有没有办法将 Koin 注入与泛型一起使用?
- android - 在 APK 中包含以下划线 (_) 开头的类加载器资源
- reactjs - 货币格式反应
- reactjs - 根据标志的值编写 React 应用程序
- python - pymssql ValueError: list.remove(x): x not in list
- javascript - 获取父列表的特定子项