颤振的景观方向布局

前端之家收集整理的这篇文章主要介绍了颤振的景观方向布局前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在横向模式下设置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,],)));

解决方法

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

the documentation

Whether this scaffold is being displayed at the top of the screen.

If true then the height of the appBar will be extended by the height of the screen’s status bar,i.e. the top padding for MediaQuery.

The default value of this property,like the default value of AppBar.primary,is 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!'),);
}

猜你在找的Flutter相关文章