在Flutter小部件测试中,如何将媒体方向设置为纵向?

5
在build方法中,MediaQuery.of(context).orientation等于Orientation.landscape。如何将其更改为portrait
测试小部件包含在MaterialApp下。

相关问题 https://github.com/flutter/flutter/issues/10307 - Günter Zöchbauer
1个回答

4

将查询方向的小部件包装在中

  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;
  }

请参阅 https://dev59.com/LFQJ5IYBdhLWcg3wg2JP。 - Günter Zöchbauer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接