58

If I have an AppBar like this:

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

3
  • 3
    Possible duplicate of How can I have clickable text in the AppBar in Flutter Commented Sep 15, 2019 at 6:32
  • Doesn't matter. Same principle. You can wrap Icon in a flat button or InkWell and have the same effect. I thought there was a lack of trying to find resources and experimenting when there were similar resources regarding making actions clickable in Appbar. Commented Sep 16, 2019 at 5:36
  • 1
    actions is list of widgets - doesn't matter what widget you put into - icon or text Commented Sep 17, 2019 at 6:30

2 Answers 2

175

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

Sign up to request clarification or add additional context in comments.

2 Comments

what if you want the icon to be on the left side?
@AntoninGAVREL, You can use the leading parameter of AppBar to add a widget (including an icon) to the left side.
53

enter image description here

Use leading for left sided icon and actions for right sided.

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),
    ),
  ],
)

2 Comments

@BoraKeçeci Please share a minimal reproducible code via Dartpad.
@BoraKeçeci if the icons are NOT visible, it is because they are taking the default primary colors of the bar, add : color: Colors.white to the IconButton and you should be fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.