英文:
Drawer's ListView doesn't show anything
问题
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.
英文:
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.
答案1
得分: 0
Drawer
将显示在父上下文的Scaffold
中,您将调用MainDrawer
的地方。从_MainDrawerState
中移除Scaffold
。
英文:
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);
},
),
],
),
);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论