【发布时间】:2022-11-04 23:05:12
【问题描述】:
我有一个列表,用户可以在其中动态添加项目。 该列表如下所示:
[{author: Tsubasa Yamaguchi, created: 24 Juin 2017, total_chapter: 34, genre: seinen, pic: https://www.nautiljon.com/images/more/03/72/278427.jpg, title: Blue Period}, {author: Tsubasa Yamaguchi, created: 24 Juin 2017, total_chapter: 34, genre: seinen, pic: https://www.nautiljon.com/images/more/03/72/278427.jpg, title: Blue Period}]
我不希望此列表中有任何重复项,因为我在 listView 中显示项目。
我尝试过list.toSet().toList() 的方法,但由于某种原因,我得到了相同的结果。
我认为这是因为格式或我的项目“{}”。
有什么建议吗?
这就是我获取列表的方式:
FirebaseFirestore firestore = FirebaseFirestore.instance;
List favMangasListTitle = [];
List detailledMangaList = [];
String title = '';
String read_chapter = '';
Future<List> getFavMangas() async {
var value = await firestore.collection("users/${user.uid}/fav_mangas").get();
final favMangasGetter = value.docs.map((doc) => doc.data()).toList();
favMangasListTitle.clear();
detailledMangaList.clear();
for (var i in favMangasGetter) {
title = i['title'];
read_chapter = i['read_chapter'];
favMangasListTitle.add(title);
}
await Future.forEach(favMangasListTitle, (i) async {
final mangas =
await firestore.collection('mangas').where('title', isEqualTo: i).get();
final receivedMangaDetailled =
mangas.docs.map((doc) => doc.data()).toList();
detailledMangaList.addAll(receivedMangaDetailled);
});
var test = detailledMangaList.toSet().toList();
print(test);
return detailledMangaList;
}
【问题讨论】:
-
您希望同一作者的元素不被复制吗?
-
不,我希望不重复具有相同标题的元素。
标签: flutter list dart duplicates