Flutter 如何将ListView.builder放入抽屉中?
我正在尝试创建一个动态菜单(通过json文件)。当我把我的代码放在身体里时,它工作得很好。但当我把它放进抽屉时,抽屉是空的,甚至我的抽屉阅读器也不见了 我的代码:Flutter 如何将ListView.builder放入抽屉中?,flutter,Flutter,我正在尝试创建一个动态菜单(通过json文件)。当我把我的代码放在身体里时,它工作得很好。但当我把它放进抽屉时,抽屉是空的,甚至我的抽屉阅读器也不见了 我的代码: Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('My App'), backgroundColor: Colors.green, ), b
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My App'),
backgroundColor: Colors.green,
),
body: ListView.builder( // <---------- WORKING
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, i) {
return new ListTile(
title: new Text(data[i]["title"]),
);
}),
drawer: Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
Container(
height: 85.0,
child: DrawerHeader(
child: Text(
'Categories',
style: new TextStyle(fontSize: 18.0, color: Colors.white),
),
decoration: BoxDecoration(
color: Colors.green,
),
),
),
ListView.builder( // <---------- NOT WORKING
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, i) {
return new ListTile(
title: new Text(data[i]["title"]),
);
})
],
),
),
);
}
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“我的应用程序”),
背景颜色:Colors.green,
),
body:ListView.builder(//您的ListView.builder
小部件需要位于具有固定高度的小部件内部
您可以在容器中设置它
:
Container(
height: double.maxFinite,
child: ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, i) {
return new ListTile(
title: new Text(data[i]["title"]),
);
}))
“不工作”到底是什么意思?@GünterZöchbauer我的抽屉是空的,我的对数没有错,你能解释一下“double.maxFinite”吗?它就像一个无穷大的数字吗?@Hotgeart