[英]How to get specific document data from firebase and return as a string
I am trying to get a data in firestore like this:我正在尝试在 Firestore 中获取数据,如下所示:
am trying to get FCMToken
from a user document And be able to immediately use it as a string inside a streambuilder我正在尝试从用户文档中获取
FCMToken
并能够立即将其用作流构建器中的字符串
FirebaseFirestore.instance.collection("usersToken")
.doc(snapshot.data.docs[index].data()['userId'].toString())
.get();
//I don't know what to do from here on to be able to get it as a string
How do I do it?我该怎么做?
It works for me这个对我有用
Widget build(BuildContext context) {
return new StreamBuilder(
stream: Firestore.instance.collection('COLLECTION_NAME').document('TEST').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
var userDocument = snapshot.data;
return new Text(userDocument["property_name"]);
}
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.