我正在尝试为纵向和横向创建不同的界面 . 在肖像中我们有一些按钮和选项,但是当我们放置横向模式时,我们只能看到一个完整尺寸的 Map .

默认方向是纵向,因此我们可以看到按钮和选项 . 我需要检测用户何时更改到landspace以显示其他元素 .

我尝试这个代码,但不起作用,没有检测屏幕方向 .

Orientation orientation = MediaQuery.of(context).orientation ;
      if (orientation == Orientation.landscape) {
            return new Scaffold(body: map);
          } else {
            return new Scaffold(
    body: BUTTONS
);

那么如何检测方向呢?

UPDATE 2 不起作用,没有检测到方向变化 .

if (loading) {
      return Scaffold(key: scaffoldKey, body: indicator);
    } else {
      return new OrientationBuilder(
  builder: (context, orientation) {
         return new Scaffold(
            key: scaffoldKey,
            body: orientation==Orientation.landscape ? new Row(children: <Widget>[map]):
  new Column(
              children: <Widget>[
                parcelSearch,
                new Expanded(
                  child: new Center(
                    child: new Container(
                      child: new Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: new Card(
                          child: ListView(
                            children: <Widget>[
                              metersElement,
                              valvesElement,
                              relesElement,
                              sensorsElement,
                            ],
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
                map,
                estateDropdown,
              ],
            ));
      });
      }