5

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

The test widget is wrap under MaterialApp.

1 Answers1

4

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;
  }
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567