Skip to content

Instantly share code, notes, and snippets.

@kleinlennart
Created May 24, 2018 15:01
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kleinlennart/3e07133274ae8ac2d1187855ce2c7e51 to your computer and use it in GitHub Desktop.
Save kleinlennart/3e07133274ae8ac2d1187855ce2c7e51 to your computer and use it in GitHub Desktop.
Flutter Custom Drawer Icon (use keys)
class _HomePageState extends State<HomePage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text("App"),
leading: new IconButton(
icon: new Icon(Icons.apps),
onPressed: () => _scaffoldKey.currentState.openDrawer())),
drawer: new Drawer());
}
}
@Uhelliton
Copy link

Nice!!!

@ammaratef45
Copy link

This is smart

@NishadAvnish
Copy link

I receive an error

openDrawer() call on null

@kleinlennart
Copy link
Author

I receive an error

openDrawer() call on null

Have you initialised the Drawer correctly and is it assigned to the drawer attribute of the Scaffold?

@WrungCodes
Copy link

you can use 'Scaffold.of(context).openDrawer()' instead

@nuelsoft
Copy link

But the dragging will stop working

@MDSADABWASIM
Copy link

you can use 'Scaffold.of(context).openDrawer()' instead

it works perfectly.

@imkurmywal
Copy link

But the dragging will stop working

It's working with me

@mannnish
Copy link

smooooth hax

@makeshyft-tom-g
Copy link

you can use 'Scaffold.of(context).openDrawer()' instead

That worked for me. :) thanks

@emirpolatt
Copy link

worked very well, thanks !

@jayrathod9002
Copy link

it's working good..thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment