Firestore数据库由一组用户组成。每个用户文档都有一些公共数据和他遵循的称为“跟随”的用户ID数组。在Flutter应用中,我想在以下数组上创建一个StreamBuilder。因此,当用户将某人添加到他的后续数组中时-该数组将添加到流中,并且当以下列表中的用户更改其数据时-该流也将更新。
我想也许使用引用列表('users/usersid3'
)而不是ID列表('userid3'
),但我不知道如何实现它。
这是数据库的结构方式。
users
- user1id
- some public data
- following: [user2id, user3id]
- user2id
- some public data
- following: []
- user3id
- some public data
- following: [user2id]
答案 0 :(得分:0)
因此,有一种解决方法可以解决此问题。
StreamBuilder(
stream: Firestore.instance.collection('users').document(uid).collection('data').document('followingDoc').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Text("No data");
return ListView.builder(
itemCount: snapshot.data['followingMap'].keys.toList().length,
itemBuilder: (BuildContext context, int index) {
return followingItemWidget(id: snapshot.data['followingMap'].keys.toList()[index]);
}
);
},
)
这很完美,尽管我相信应该只有一种StreamBuilder可以做到这一点。