英文:
ListView.builder with Wrap widget duplicates data
问题
我有一个包含日期的列表。我使用ListView.builder中的Wrap小部件显示这个日期列表,数据显示出来,但出现了重复...
如何去除重复项?
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: days == null ? 0 : days.length,
itemBuilder: (BuildContext context, int index) {
return Wrap(
children: <Widget>[
...days.map((date) {
return Container(
width: MediaQuery.of(context).size.width / 2.4,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
color: Colors.white,
),
child: ListTile(
onTap: () {
Navigator.pushNamed(context, '/logEntry');
},
title: const DefaultText(
size: 18,
text: "Day 1",
color: Colors.green,
weight: FontWeight.w500,
),
subtitle: DefaultText(
size: 15,
text: "${date.day}/${date.month}/${date.year}".toString(),
color: Colors.green,
weight: FontWeight.w500,
),
trailing: const Icon(Icons.arrow_forward_ios),
),
);
}).toList(),
],
);
},
),
英文:
I have a list which contains days. I displayed this list of days using Wrap widget in a ListView.builder, the data displays but it duplicates...
How can I remove the duplications?
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: days == null ? 0 : days.length,
itemBuilder: (BuildContext context, int index) {
return Wrap(
children: <Widget>[
...days.map((date) {
return Container(
width: MediaQuery.of(context).size.width / 2.4,
decoration: const BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(20.0)),
color: Colors.white,
),
child: ListTile(
onTap: () {
Navigator.pushNamed(context, '/logEntry');
},
title: const DefaultText(
size: 18,
text: "Day 1",
color: Colors.green,
weight: FontWeight.w500,
),
subtitle: DefaultText(
size: 15,
text: "${date.day}/${date.month}/${date.year}"
.toString(),
color: Colors.green,
weight: FontWeight.w500,
),
trailing: const Icon(Icons.arrow_forward_ios),
),
);
}).toList(),
],
);
},
),
答案1
得分: 0
你不需要像这样使用ListView.builder
,只需像这样使用ListView
来处理高度溢出。
ListView(
children: [
Wrap(),
],
),
英文:
You don't need to use ListView.builder
like with wrap like this. You can shift to ListView
just to handle height-overflow.
ListView(
children: [
Wrap(),
],
),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论