In this example, I will share how to hide drawer in flutter after changing Scaffold.body value. Are you using exactly Navigator.of(context).pop()? I cannot reproduce your problem, can you post a minimal example to reproduce it?
The following code works as expected: the settings button pops away the drawer, while the other don’t.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => new _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { String text = "Initial Text"; @override Widget build(BuildContext context) { return new Scaffold( drawer: new Drawer( child: new ListView( children: <Widget>[ new Container(child: new DrawerHeader(child: new Container())), new Container ( child: new Column( children: <Widget>[ new ListTile(leading: new Icon(Icons.info), onTap:(){ setState((){ text = "info pressed"; }); } ), new ListTile(leading: new Icon(Icons.save), onTap:(){ setState((){ text = "save pressed"; }); } ), new ListTile(leading: new Icon(Icons.settings), onTap:(){ setState((){ text = "settings pressed"; }); Navigator.of(context).pop(); } ), ] ), ) ], ), ), appBar: new AppBar(title: new Text("Test Page"),), body: new Center(child: new Text((text)), )); } } |
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.