Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add icon to AppBar in Flutter

If I have an AppBar like this:

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

like image 562
Suragch Avatar asked Sep 15 '19 04:09

Suragch


People also ask

How do you put icons on AppBar flutter?

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

How do you add icons to icon on flutter?

The simplest way to create a button with icon and text in Flutter is to use the new Material button called ElevatedButton with an icon constructor. ElevatedButton. icon() gives you the ability to add the icon and label parameter to the button. The ElevatedButton was introduced with the release of Flutter v1.


2 Answers

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

  • AppBar Basics documentation
  • How can I have clickable text in the AppBar in Flutter
like image 142
Suragch Avatar answered Sep 28 '22 02:09

Suragch


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),     ),   ], ) 
like image 30
iDecode Avatar answered Sep 28 '22 00:09

iDecode