By default, the endDrawer icon in flutter is the hamburger icon. I wanna change it to a filter icon.
new Scaffold(
endDrawer: Drawer(),
...
}
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.
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.
you can do this in drawer: Widget drawer(BuildContext context) { return Drawer( child: ListView( padding: EdgeInsets. zero, children: <Widget>[ Container( ... ) ); then your appbar.
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.
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.
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