我的列表 View 是相反的顺序。我想在listView反向模式的最后一个索引中添加自定义项目吗? (至第一项)
return ListView.builder(
itemCount: snapshot.data.length + 1,
reverse: true,
itemBuilder: (BuildContext context, int index) {
if (index == snapshot.data.length -1) {
return Container(
child: myEnquiry());
}
index -= 1;
return other_widget();
}
);
最佳答案
return ListView.builder(
itemCount: snapshot.data.length + 1,
reverse: true,
itemBuilder: (BuildContext context, int index) {
if (index == 0) { // Fix this line.
return Container(child: myEnquiry());
}
index -= 1;
return other_widget();
},
);
要么
return ListView.builder(
itemCount: snapshot.data.length + 1,
reverse: true,
itemBuilder: (BuildContext context, int index) {
if (index == snapshot.data.length) { // Fix this line.
return Container(child: myEnquiry());
}
// index -= 1; // Fix this line.
return other_widget();
},
);
关于flutter - 如何将自定义项目添加到listView反向模式的最后一个索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59912110/