在Flutter Widget测试中,如何使media.orientation成为纵向? [英] In Flutter Widget testing, how to make media.orientation to portrait?

查看:112
本文介绍了在Flutter Widget测试中,如何使media.orientation成为纵向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建方法中,MediaQuery.of(context).orientation等于Orientation.landscape.如何使其成为portrait.

In build method, MediaQuery.of(context).orientation equals Orientation.landscape. How to make it into portrait.

测试窗口小部件包装在MaterialApp下.

The test widget is wrap under MaterialApp.

推荐答案

包装查询方向的小部件

  MediaQuery(
    data: MediaQueryData
        .fromWindow(ui.window)
        .copyWith(size: const Size(600.0, 800.0)),
    child: widgetToTest,
  )

为我工作.

MediaQuery.orientation只是检查哪个尺寸更大

MediaQuery.orientation just checks what dimension is bigger

  Orientation get orientation {
    return size.width > size.height ? Orientation.landscape : Orientation.portrait;
  }

这篇关于在Flutter Widget测试中,如何使media.orientation成为纵向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆