How to add icon to AppBar in Flutter

Suragch picture Suragch · Sep 15, 2019 · Viewed 61.1k times · Source

If I have an AppBar like this:

How do I add a clickable icon to it like this?

Answer

Suragch picture Suragch · Sep 15, 2019

You can add an icon to the AppBar by adding an IconButton widget to the actions list of the AppBar.

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

See also