i’m trying to make a drawer for my app, but it doesn’t show anything i want it to show for some reason. The console doesn’t throw any errors, so i have no idea what happened. Can anyone tell me why?
class _MainDrawerState extends State<MainDrawer> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.cyan,
),
child: Text(
'DBug',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
ListTile(
title: const Text('item 1'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: const Text('item 2'),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
);
}
}
i tried making it both a stateless and a stateful widget, didn’t help in either.
>Solution :
Drawer will be showed on parent context scaffold, the place you will call MainDrawer. remove Scaffold from _MainDrawerState .
class _MainDrawerState extends State<MainDrawer> {
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.cyan,
),
child: Text(
'DBug',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
ListTile(
title: const Text('item 1'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: const Text('item 2'),
onTap: () {
Navigator.pop(context);
},
),
],
),
);
}
}