Want to open drawer on clicking AppBar in Flutter? Use a Key in your Scaffold and show the drawer by calling myKey.currentState.openDrawer(), here is a working code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import "package:flutter/material.dart"; class Test extends StatefulWidget { @override _TestState createState() => new _TestState(); } class _TestState extends State<Test> { final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); @override Widget build(BuildContext context) { return new Scaffold( key: _scaffoldKey, drawer: new Drawer(), appBar: new AppBar( leading: new IconButton(icon: new Icon(Icons.settings), onPressed: () => _scaffoldKey.currentState.openDrawer()), ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.