flutter - 在 Flutter Widget 测试中,如何将 media.orientation 设置为纵向?
问题描述
在构建方法中,MediaQuery.of(context).orientation
等于Orientation.landscape
。怎么弄成portrait
。
测试小部件包裹在MaterialApp
.
解决方案
包装查询方向的小部件
MediaQuery(
data: MediaQueryData
.fromWindow(ui.window)
.copyWith(size: const Size(600.0, 800.0)),
child: widgetToTest,
)
为我工作。
MediaQuery.orientation
只检查哪个维度更大
Orientation get orientation {
return size.width > size.height ? Orientation.landscape : Orientation.portrait;
}
推荐阅读
- java - 创建参数化构造函数以确定随机边长的上限
- powershell - 如何扩展变量中的属性
- python-3.x - PDFkit 无法读取 html 以转换为 pdf(html 文件存在)
- angular - Angular 13 库项目中的动态模板
- ios - 如何禁用我的 UITabBarController 的 moreNavigationController 的某些选项卡?
- amazon-web-services - AWS 金属实例:无法启用 IOMMU
- eclipse - PHP 8 脚本在带有 Eclipse 2020-06 的 Chrome 上运行
- flutter - Flutter - 断言失败:assetName!= null 不正确
- mysql - SQL 语法问题:如何获取前 4 个字母和大写字母
- python-3.x - python中相互依赖的静态方法