带Firestore的StreamBuilder中的嵌套查询

时间:2019-02-13 01:48:40

标签: flutter google-cloud-firestore

我有一组帖子(/posts),每个帖子都引用了作者的ID(在/users中),我想知道,有没有一种方法可以在其中使用streambuilder进行双重查询扑(获取帖子信息,然后针对每个帖子查询authorID的用户信息)?如果不是,最好的方法是什么? :)

我的消防站结构示例:

- posts
   - postID
      - authorID
      - text
      - timestamp
      - otherfields...

- users
   - userID
      - name
      - email
      - otherfields

1 个答案:

答案 0 :(得分:0)

我认为没有其他流就无法进行Firestore查询。我是通过StreamZip或嵌套的StreamBuilders解决此问题的方法。

stream: new StreamZip([stream1, stream2])

return StreamBuilder<FirebaseUser>(
  stream: FirebaseAuth.instance.currentUser().asStream(),
  builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
    return StreamBuilder(
      stream: Firestore.instance.document('my_collection/$uid').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {