I'm new to flutter and exploring it. I already have an app bar but I can't seem to figure out how to properly display a drawer icon and a search icon on it. I want it to look like the gmail app bar like the image below. I am working on a company helpdesk mobile app. Thanks.
Add the Search View to the App Bar To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.
To change the drawer icon in Flutter, add an IconButton widget inside the leading property of the AppBar widget. Inside the IconButton you can set any icon of your choice. Then, inside the onPressed of an IconButton, you can write a method to open the drawer.
You can try this code....
appBar: AppBar(
leading: Builder(
builder: (BuildContext context){
return IconButton(
icon: Icon(Icons.menu),
onPressed: () {
},
);
}),
title: Text("Flutter App"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {
},
),
IconButton(
icon: Icon(Icons.search),
onPressed: () {
},
)
],
),
Do it as stated in the flutter docs.
new AppBar(
title: new Text('My Fancy Dress'),
actions: <Widget>[
new IconButton( icon: new Icon(Icons.playlist_play), tooltip: 'Air it', onPressed: _airDress, ),],
leading: <Widget>[
new IconButton( icon: new Icon(Icons.playlist_play), tooltip: 'Air it', onPressed: _airDress, ),
], )
Where the widget under leading is the drawer and the one under actions is the search iconbutton.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With