Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the endDrawer icon in flutter?

Tags:

flutter

dart

By default, the endDrawer icon in flutter is the hamburger icon. I wanna change it to a filter icon.

new Scaffold(
  endDrawer: Drawer(),
  ...
}
like image 353
Rachit Rawat Avatar asked Aug 21 '18 23:08

Rachit Rawat


People also ask

How do I change the icon on my drawer icon 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.

What is EndDrawer in flutter?

EndDrawer. The EndDrawer is typically used to provide navigation to other pages. The EndDrawer opens up from the right side of the screen by swiping right-to-left or clicking the menu icon in the AppBar. The EndDrawer can be closed by clicking outside of the EndDrawer or by swiping left-to-right.

How do I change the size of the drawer icon in flutter?

you can do this in drawer: Widget drawer(BuildContext context) { return Drawer( child: ListView( padding: EdgeInsets. zero, children: <Widget>[ Container( ... ) ); then your appbar.

How do I add EndDrawer to flutter?

The endDrawer is the panel displayed to the side of the body (Scaffold Widget). It is generally hidden in mobile devices. We can open it by swiping in from right to left, or we can customise it to open on-press of an icon or a button.


1 Answers

This should do what you want:

import 'package:flutter/material.dart';

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        endDrawer: Drawer(),
        appBar: AppBar(
          actions: [
            Builder(
              builder: (context) => IconButton(
                    icon: Icon(Icons.filter),
                    onPressed: () => Scaffold.of(context).openEndDrawer(),
                    tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
                  ),
            ),
          ],
        ),
        body: new Container(),
      ),
    );
  }
}

void main() => runApp(App());

Note the 'Builder' is necessary so that the IconButton gets the context underneath the Scaffold. Without that, it would instead be using the context of the App and therefore wouldn't be able to find the Scaffold.

A different (cleaner?) option would be to make a StatelessWidget that encloses IconButton.

like image 129
rmtmckenzie Avatar answered Oct 02 '22 05:10

rmtmckenzie