In Flutter Widget testing, how to make media.orientation to portrait?

后端 未结 1 557
青春惊慌失措
青春惊慌失措 2020-12-18 10:03

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

The test widge

相关标签:
1条回答
  • 2020-12-18 11:02

    Wrapping the widgets that query orientation in

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

    worked for me.

    MediaQuery.orientation just checks what dimension is bigger

      Orientation get orientation {
        return size.width > size.height ? Orientation.landscape : Orientation.portrait;
      }
    
    0 讨论(0)
提交回复
热议问题