更新时间:2021-11-23 19:01:40
仅循环遍历从firebase中获得的主题标签,然后仅将其添加到结果中(如果它们还没有在其中):
Just loop over the hashtags you get from firebase and add them to your results only if they are not already in there like this:
Future<List<String>> getHashtags() async {
List<String> allVideoHastags = [];
QuerySnapshot snapshots =
await FirebaseFirestore.instance.collection('videos').get();
for (QueryDocumentSnapshot videoSnapshot in snapshots.docs) {
List<String> videoHastags =
List.from(videoSnapshot.data()['Hashtagsforallvideos']);
videoHastags.forEach((element) {
if(!allVideoHastags.contains(element)){
allVideoHastags.add(element);
}
});
}
_allResults = allVideoHastags;
searchResults();
return allVideoHastags;
}