颤振的景观方向布局

时间:2017-10-09 14:52:00

标签: layout landscape flutter

如何在横向模式下设置AppBar高度,使其不占用屏幕填充?

enter image description here

是否有通常的Flutter景观布局小工具?上述问题布局如下:

new Padding(
  padding: media.padding,
  child: new Scaffold(
      key: _scaffoldKey,
      body: new Row(
        children: <Widget>[
          new LimitedBox(
            maxWidth: 320.0,
            child: new Column(children: [
              _buildAppBar(),
              new Expanded(
                  child: new ModuleDrawer(
                widget.module.sugar,
                topPadding: 0.0,
              )),
            ]),
          ),
          new Expanded(
            child: new RecordList(
              widget.model,
            ),
          ),
        ],
      )));

1 个答案:

答案 0 :(得分:9)

你可以使用脚手架的primary属性,结合通过简单的MediaQuery检测方向。因此,在横向模式下,将primary标记设置为false,以告知Scaffold在确定AppBar高度时不考虑状态栏高度。

请参阅the documentation

  

此脚手架是否显示在屏幕顶部。

     

如果为true,那么appBar的高度将扩展到屏幕状态栏的高度,即MediaQuery的顶部填充。

     

此属性的默认值(如AppBar.primary的默认值)为true。

所以在你的情况下,这样的事情应该做:

@override
Widget build(BuildContext context) {
    final Orientation orientation = MediaQuery.of(context).orientation;
    final bool isLandscape = orientation == Orientation.landscape;

    return new Scaffold(
        primary: !isLandscape,
        appBar: new AppBar(
          title: new Text('AppBar title'),
        ),
        body: new Center(
            child: new Text('Look at the appbar on landscape!'),
        ),
    );
}
相关问题