I have been playing around with the drawer and the items inside change some buttons in the body of the scaffold.
What can I do to have this drawer close when the user clicks on an item?
I have used the Navigator.POP(context);
however it will not close the drawer.
Here is my code:
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
int _modIndex = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(child: Text('Choose a mod'),),
ListTile(
title: const Text('Wheels'),
onTap: () {
setState(() {
_modIndex = 0;
});
Navigator.pop(context);
},
),
ListTile(
title: const Text('Suspension'),
onTap: () {
setState(() {
_modIndex = 1;
});
Navigator.pop(context);
},
),
ListTile(
title: const Text('Body Colour'),
onTap: () {
setState(() {
_modIndex = 2;
});
Navigator.pop(context);
},
)
],
),
...
I'm not sure what is wrong.