如何在 Flutter 中为 AppBar 添加图标

Sur*_*gch 27 icons flutter flutter-appbar

如果我有这样的 AppBar:

我如何像这样添加一个可点击的图标?

Sur*_*gch 108

您可以通过向 AppBaractions列表添加 IconButton 小部件来向 AppBar 添加图标。

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

也可以看看

  • @AntoninGAVREL,您可以使用“AppBar”的“leading”参数在左侧添加一个小部件(包括图标)。 (4认同)

iDe*_*ode 46

在此输入图像描述

用于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),
    ),
  ],
)
Run Code Online (Sandbox Code Playgroud)