簡體   English   中英

從firestore中的集合中獲取所有文檔

[英]Get all documents from collection in firestore

我正在嘗試從我的“instagram”克隆應用程序中獲取所有帖子。 這是我在 Firestore 中的路徑: posts > (unique ownerId) > userPosts > (unique postId)

如何使用 stream 構建器檢索所有帖子? 我試着這樣做

body:
StreamBuilder<QuerySnapshot>(
          stream: postsRef.snapshots(),
          builder: (context, snapshot) {
            if (!snapshot.hasData) {
              return circularProgress();
            }
            List<Post> posts = snapshot.data.documents.map((doc) =>  Post.fromDocument(doc)).toList();
            return ListView(children: posts);
          },
        )

我只想在一堆卡片中顯示帖子的圖片。

Cloud Firestore 中的偵聽器不能使用通配符。 您需要在路徑中命名具體的文檔和collections。 因此,如果在查詢時您的(unique ownerId)未知,您將無法知道有關其子集合中更改的文檔的任何信息。

作為替代方案,在您控制的后端,您可以列出文檔的子集合,然后查詢這些文檔。 或者,您可以使用 Cloud Functions 觸發器並在發生更改時通知感興趣的客戶端應用程序(可能使用雲消息傳遞)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM