34

如果我有这样的 AppBar:

如何像这样向它添加可点击的图标?

4

2 回答 2

116

您可以通过将 IconButton 小部件添加到 AppBar 的actions列表来将图标添加到 AppBar。

AppBar(
  title: Text('My App'),
  actions: <Widget>[
    IconButton(
      icon: Icon(
        Icons.settings,
        color: Colors.white,
      ),
      onPressed: () {
        // do something
      },
    )
  ],
),

也可以看看

于 2019-09-15T04:45:54.767 回答
12

在此处输入图像描述

用于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),
    ),
  ],
)
于 2021-07-09T15:08:02.813 回答