【发布时间】:2019-05-27 23:15:19
【问题描述】:
这是我的代码,复制自here:
SliverAppBar(
expandedHeight: 150.0,
flexibleSpace: const FlexibleSpaceBar(
title: Text('Available seats'),
),
actions: < Widget > [
IconButton(
icon: const Icon(Icons.add_circle),
tooltip: 'Add new entry',
onPressed: () { /* ... */ },
),
]
)
但我需要添加一个Drawer。我该怎么做?
我正在尝试在 Flutter 中重建我的应用程序。
Converting java android app to flutter
我替换了图标,但如何创建Drawer?
leading: IconButton(icon: Icon( Icons.menu ),onPressed: ()=>{},)
我的完整代码
@override
Widget build(BuildContext context) {
return NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () => {},
),
actions: <Widget>[
IconButton(
onPressed: () => {},
icon: Icon(Icons.shopping_cart),
)
],
expandedHeight: 200.0,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("My Pet Shop",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Image.network(
"https://firebasestorage.googleapis.com/v0/b/my-pet-world.appspot.com/o/images%2Fbannerads%2FxTmAblJI7fMF1l0nUa1gM32Kh9z1%2F734rm6w7bxznp%2FPETWORLD-HOME-SLIDER-KITTENS.webp?alt=media&token=cf7f48bb-6621-47b3-b3f8-d8b36fa89715",
fit: BoxFit.cover,
)),
),
];
},
body: Container(
margin: EdgeInsets.only(top: 0),
child: Column(
children: <Widget>[
Expanded(
//getHomePageWidget()
child: ListView(
padding: EdgeInsets.all(0.0),
children: <Widget>[getHomePageWidget()],
),
)
],
),
));
}
【问题讨论】:
-
您不需要在 SliverAppBar 中手动添加菜单图标。当您将 Scaffold 作为其祖先时,菜单图标会神奇地出现。
-
你能用我的新代码更新一下吗
-
在我的新代码中添加脚手架的位置?
-
我刚做了。你的正文代码有很多不必要的代码,所以我把它们都去掉了,剩下的是 getHomePageWidget()。
标签: dart flutter flutter-layout flutter-sliver