【问题标题】:In Flutter Widget testing, how to make media.orientation to portrait?在 Flutter Widget 测试中,如何将 media.orientation 设置为纵向?
【发布时间】:2018-10-13 23:07:44
【问题描述】:

在构建方法中,MediaQuery.of(context).orientation 等于 Orientation.landscape。怎么变成portrait

测试小部件包裹在MaterialApp 下。

【问题讨论】:

标签: flutter ui-testing


【解决方案1】:

包装查询方向的小部件

  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;
  }
猜你喜欢
  • 2020-12-26
  • 2019-11-04
  • 2021-08-17
  • 2020-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-09
相关资源
最近更新 更多