作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
- posts
- userID
- userID
- randomID
- randomID
- followers
- personB userid
- personA userid
- following
- personA userid
- personB userid
这就是我的Firebase集合的组织方式。
getFollowing() async {
QuerySnapshot snapshot = await followersRef
.document(currentUser.id)
.collection('userFollowing')
.getDocuments();
setState(() {
followingList = snapshot.documents.map((doc) => doc.documentID).toList();
print(followingList);
});
}
getTimeline()async{
QuerySnapshot snapshot = await postsRef
.document(followingList)//getting an error here saying list<string> csn't be assigned to string.
.collection('userPosts')
.orderBy('timestamp', descending: true)
.getDocuments();
List<Post> posts =
snapshot.documents.map((doc) => Post.fromDocument(doc)).toList();
setState(() {
this.posts = posts;
});
}
最佳答案
List timelinePosts =[];
getFollowing() async {
QuerySnapshot snapshot = await followersRef
.document(currentUser.id)
.collection('userFollowing')
.getDocuments();
setState(() {
followingList = snapshot.documents.map((doc) => doc.documentID).toList();
print(followingList);
});
}
getTimeline()async{
List posts = [];
for( int i=0; i< followingList.length; i++)
{
QuerySnapshot snapshot = await postsRef
.collections('posts/${followingList[i]}/userPosts')
.orderBy('timestamp', descending: true)
.getDocuments();
posts+= snapshot.data.documents.map((doc) => {'id':doc.documentID,...doc.data}).toList();
}
setState(() {
timelinePosts = timeLinePosts + posts;
});
}
然后您可以在timelinePosts上使用Listview.builder(),
关于firebase - 如何在Flutter中使用Firebase创建时间轴供稿?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62591107/
我是一名优秀的程序员,十分优秀!