与抽屉式导航栏建设appbar:
@override
Widget build(BuildContext context) {
var drawerOptions = <Widget>[];
for (var i = 0; i < widget.drawerItems.length; i++) {
var d = widget.drawerItems[i];
drawerOptions.add(new ListTile(
leading: new Icon(d.icon),
title: new Text(d.title),
selected: i == _selectedDrawerIndex,
onTap: () => _onSelectItem(i),
));
}
drawerOptions.add(
new RaisedButton(onPressed: () => {}, child: new Text("Ustawienia")));
return new Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 130.0,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title:
new Text(widget.drawerItems[_selectedDrawerIndex].title),
),
),
];
},
body: _getDrawerItemWidget(_selectedDrawerIndex),
),
drawer: new Drawer(
child: new Column(
children: <Widget>[
new UserAccountsDrawerHeader(
accountName: new Text("Gość"), accountEmail: null),
new Column(children: drawerOptions)
],
),
));
结果:
因此,有不需要的白色边缘正上方的身体。如果我尝试定期appbar,这种方式:
return new Scaffold(
appBar: new AppBar(
// here we display the title corresponding to the fragment
// you can instead choose to have a static title
title: new Text(widget.drawerItems[_selectedDrawerIndex].title),
),
drawer: new Drawer(
child: new Column(
children: <Widget>[
new UserAccountsDrawerHeader(
accountName: new Text("Gość"), accountEmail: null),
new Column(children: drawerOptions)
],
),
),
body: _getDrawerItemWidget(_selectedDrawerIndex),
);
结果是好的,没有任何额外的保证金:
如何删除不需要的额外保证金和调整标题处于扩展状态到左(它应该在汉堡的菜单指示灯被放置)。
DrawerItem
类的定义:
class DrawerItem {
String title;
IconData icon;
DrawerItem(this.title, this.icon);
}
drawerItems
定义如下:
final drawerItems = [
new DrawerItem("Option1", Icons.list),
new DrawerItem("Option2", Icons.event_note),
new DrawerItem("Option3", Icons.account_balance),
//... etc
];
我面临着一个嵌套的滚动视图同样的问题。我使用的是网格视图的身体和填充设置为0,摆脱了空间的
GridView.builder(
padding: EdgeInsets.only(top: 0),
所以不管你的小部件从这种方法qazxsw诗返回添加填充它。
_getDrawerItemWidget(_selectedDrawerIndex)
更多信息:Widget _getDrawerItemWidget(){
return MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView.builder(
.......
)
);
}