如何在Flutter中为AppBar添加图标
How to add icon to AppBar in Flutter
如果我有这样的 AppBar:
如何给它添加一个可点击的图标?
您可以通过将 IconButton 小部件添加到 AppBar 的 actions
列表来将图标添加到 AppBar。
AppBar(
title: Text('My App'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.settings,
color: Colors.white,
),
onPressed: () {
// do something
},
)
],
),
另见
左侧图标使用 leading
,右侧图标使用 actions
。
AppBar(
centerTitle: true,
title: Text('AppBar'),
leading: IconButton(
onPressed: () {},
icon: Icon(Icons.home),
),
actions: [
IconButton(
onPressed: () {},
icon: Icon(Icons.call),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.more_vert),
),
],
)
如果我有这样的 AppBar:
如何给它添加一个可点击的图标?
您可以通过将 IconButton 小部件添加到 AppBar 的 actions
列表来将图标添加到 AppBar。
AppBar(
title: Text('My App'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.settings,
color: Colors.white,
),
onPressed: () {
// do something
},
)
],
),
另见
左侧图标使用 leading
,右侧图标使用 actions
。
AppBar(
centerTitle: true,
title: Text('AppBar'),
leading: IconButton(
onPressed: () {},
icon: Icon(Icons.home),
),
actions: [
IconButton(
onPressed: () {},
icon: Icon(Icons.call),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.more_vert),
),
],
)