Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a drawer and a search icon on my app bar in flutter

Tags:

flutter

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.

gmail app bar

like image 850
Principiante Avatar asked Jun 29 '18 01:06

Principiante


People also ask

How do I add a search icon to my app bar?

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.

How do you add an icon to a drawer in Flutter?

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.


2 Answers

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: () {
            },
          )
        ],
      ),
like image 78
Parth Avatar answered Oct 15 '22 23:10

Parth


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.

like image 33
Bostrot Avatar answered Oct 15 '22 23:10

Bostrot