简体   繁体   English

如何从firebase中获取特定文档数据并以字符串形式返回

[英]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.

相关问题 如何从refrenced文档(Firebase)中的字段获取String数据 - How to get String data from field inside a refrenced document (Firebase) 如何在准备好的文档中从Firebase获取数据 - How to get data from Firebase on document ready 如何从 firebase 文档中获取数据? - how to get data from firebase document? 如何从firebase获取特定的子数据 - How to get specific child data from firebase 如何使用 Kotlin 从 Firebase 获取特定数据 - How to get specific data from Firebase with Kotlin Flutter Firebase - 从文档中获取特定字段 - Flutter Firebase - Get a specific field from document Firebase Reactjs:如何使用where子句获取firebase中特定文档的数据,然后显示数据? - Firebase Reactjs: How to get data of specific document in firebase using where clause, and then displaying the data? 如何从firebase文档中获取数据以存储它并以另一种方法使用它 - How to get data from firebase document to store it and use it in another method 如何使用 TypeScript 从 Firebase Firestore 文档中获取数据字段? - How to get a data field from a Firebase Firestore document using TypeScript? 如何检查从Firebase数据库获取的特定字符串以过滤接收到的数据? - How do I check for a specific string to get from a Firebase Database to filter what data is received?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM