Flutter Listview 不显示所有项目
Flutter Listview not displaying all items
我有一个列表视图,它应该显示来自 firebase 的项目流。在每两个项目之后有一个正在显示的自定义小部件,为了实现这一点,我使用 if else 语句。现在的问题是我的自定义小部件正在覆盖 firebase 中的一些项目,这样如果流中总共有 5 个项目,我只会得到 3 个,另外 2 个被我的自定义小部件替换。有没有办法获取包括自定义小部件在内的所有项目,以便(按照上面的示例)我总共可以拥有 7 个项目?这是我的代码供参考
StreamBuilder(
stream: stream,
//stream: getposts(),
builder: (BuildContext context,
AsyncSnapshot<List<DocumentSnapshot>>snapshots) {
return Flexible(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
if(index % 2 == 0 && index != 0){
return Container(child: Text("Custom Widget")) //this is the code inserting custom widget into the listview
else{ Container(child: Text(snapshots.data.title))
}
}))
}
你能像这样使用专栏吗(?)
if(index % 2 == 0 && index != 0){
return Column(
children: [
Container(child: Text("Custom Widget")),
Container(child: Text(snapshots.data.title)),
]
);
} else {
return Container(child: Text(snapshots.data.title))
}
我有一个列表视图,它应该显示来自 firebase 的项目流。在每两个项目之后有一个正在显示的自定义小部件,为了实现这一点,我使用 if else 语句。现在的问题是我的自定义小部件正在覆盖 firebase 中的一些项目,这样如果流中总共有 5 个项目,我只会得到 3 个,另外 2 个被我的自定义小部件替换。有没有办法获取包括自定义小部件在内的所有项目,以便(按照上面的示例)我总共可以拥有 7 个项目?这是我的代码供参考
StreamBuilder(
stream: stream,
//stream: getposts(),
builder: (BuildContext context,
AsyncSnapshot<List<DocumentSnapshot>>snapshots) {
return Flexible(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
if(index % 2 == 0 && index != 0){
return Container(child: Text("Custom Widget")) //this is the code inserting custom widget into the listview
else{ Container(child: Text(snapshots.data.title))
}
}))
}
你能像这样使用专栏吗(?)
if(index % 2 == 0 && index != 0){
return Column(
children: [
Container(child: Text("Custom Widget")),
Container(child: Text(snapshots.data.title)),
]
);
} else {
return Container(child: Text(snapshots.data.title))
}