颤振与振动;Firebase:有没有办法将特定字段从Firebase返回到函数?

颤振与振动;Firebase:有没有办法将特定字段从Firebase返回到函数?,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我的目标是从文档中返回用户的密钥,然后能够在其他功能中使用该密钥 getUsersKey() async { final uid = await getCurrentUser(); Firestore.instance.collection('users').document(uid).get(); // Then I want to return the userKey feild } 您可以编写以下代码: Future<void> getUsers

我的目标是从文档中返回用户的密钥,然后能够在其他功能中使用该密钥

  getUsersKey() async {
   final uid = await getCurrentUser();
   Firestore.instance.collection('users').document(uid).get();
   // Then I want to return the userKey feild 
  }

您可以编写以下代码:

 Future<void> getUsersKey() async {
   final uid = await getCurrentUser();

 DocumentSnapshot snapshot = 
 await Firestore.instance.collection('users').document(uid).get();
  userKey = snapshot.data['userKey'] //you can get any field value you want by writing the exact fieldName in the data[fieldName]
  }
Future getUsersKey()异步{
最终uid=等待getCurrentUser();
DocumentSnapshot快照=
等待Firestore.instance.collection('users').document(uid.get();
userKey=snapshot.data['userKey']//您可以通过在数据[fieldName]中写入确切的字段名来获得任何想要的字段值
}

此问题不适用于Firebase实时数据库。请正确标记。是否要获取文档id?否,我要获取其中一个字段(userKey)。如果你点击链接,你可以看到我想要的字段。难道你不喜欢堆栈溢出吗!谢谢你Morez,它起作用了。很乐意帮忙。请接受答案,让其他人知道它是有效的。谢谢:)