颤振的景观方向布局

Kya*_*Tun 5 layout landscape flutter

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

在此输入图像描述

是否有通常的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,
            ),
          ),
        ],
      )));
Run Code Online (Sandbox Code Playgroud)

Iir*_*kka 9

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

查看文档:

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

如果为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!'),
        ),
    );
}
Run Code Online (Sandbox Code Playgroud)