2017-10-09 128 views
2

如何设置AppBar高度在横向模式下,这样它不占用丝网填充?扑横向布局

enter image description here

是否有一个通常的颤振景观布局工具?上述问题的布局如下:

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, 
      ), 
     ), 
     ], 
    ))); 

回答

3

你也许可以使用支架的primary财产,在通过简单的MediaQuery检测取向组合。因此,在风景模式,设置primary标志设置为false告诉Scaffold确定AppBar高度时,未采取状态栏的高度考虑进去。

the documentation

无论是在屏幕的顶部显示此支架。

如果为true,则appBar的高度将被屏幕状态栏的高度(即MediaQuery的顶部填充)扩展。

此属性的默认值,像AppBar.primary的默认值,是真实的。

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

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

    return new Scaffold(
     primary: isLandscape? false : true, 
     appBar: new AppBar(
      title: new Text('AppBar title'), 
     ), 
     body: new Center(
      child: new Text('Look at the appbar on landscape!'), 
     ), 
    ); 
} 
+0

节省时间;)THX。我用您的解决方案,以使基于用例风景模式 – toregua

+0

扑画廊动画插件工作时,你也可以使用[OrientationBuilder(https://docs.flutter.io/flutter/widgets/OrientationBuilder-class.html) 。而不是依赖设备的方向的,它是基于父窗口部件的比例。 –