Flutter Firebase循环处理文档中的集合 [英] Flutter Firebase Loop over collection in a document
本文介绍了Flutter Firebase循环处理文档中的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中有以下路径:
I have this path in my Database:
/messages/tT2Q16n1FMZoTNZQOejtWuJdCmD2/ZqihbgR7skcytLAe88fQecmxcIc2-tT2Q16n1FMZoTNZQOejtWuJdCmD2/1579626761580
从这里我必须获得 content
.
我正在尝试:
var snapshot = Firestore.instance.collection('messages').document(user.id).snapshots();
但是如何遍历这些项目并从每个馆藏中获取内容?
but how can I loop over these items and get content from each collection?
然后在我的UI中,我要打印此内容消息:
And then in my UI I want to print this content message:
Container(
child: Text(
'Content: ${document['content']}',
style: TextStyle(color: primaryColor),
),
alignment: Alignment.centerLeft,
margin: EdgeInsets.fromLTRB(10.0, 0.0, 0.0, 5.0),
),
推荐答案
Firestore的客户端SDK无法请求集合列表.因此,您将需要以一种可以已经嵌入到代码中的方式来命名集合,或者使用一个Admin SDK来获取集合名称列表,并以某种方式将其公开给客户端代码(例如通过Cloud Functions).
The client-side SDKs for Firestore have no way to request a list of collections. For this reason you'll either need to name your collections in a way that you can embed in your code already, or use one of the Admin SDKs to get a list of collection names and expose that to your client-side code in some way (for example through Cloud Functions).
另请参阅: