I'm currently making a Flutter app for practice, similar to a Twitter clone app. However, I have a problem when I try to get all documents from Firestore Database. I use UID as document id and want to see all user's posts. But only the posts of the currently logged in user are displayed.
In this case, how can I get all the documents?
I want to display posts by user [B1vq9.........] and posts by [QVf5.........].
I tried:
final FirebaseAuth auth = FirebaseAuth.instance;
final User? user = auth.currentUser;
final uid = user!.uid;
FirebaseFirestore.collection('post').doc(uid).collection('talk').snapshots();
However, this code can only display posts from the currently logged in user.
collection('talk')
is a subcollection. enter image description here
If you need all the posts from posts
's collection you only need
FirebaseFirestore.collection('post').snapshots()
If you append .doc(uid).collection('talk')
then this will fetch all the documents inside {uid}/talk
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.