firebase - Flutter & Firebase:有没有办法可以将特定字段从 firebase 返回到函数?
问题描述
我的目标是从文档中返回用户的密钥,然后能够在其他功能中使用该密钥。
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]
}
推荐阅读
- authentication - 如何在剧作家中使用 MFA?
- php - PHP 警告:extract() 期望参数 1 是数组
- github - 跨多个 github 存储库管理问题
- laravel - 如何在 laravel 中集成来自 autocad forge 的 BIM 360 API?
- r - 将 RasterLayer 导出为 shapefile(从 R 到 QGIS)
- javascript - 选择多个复选框后如何检查是否有任何值保存在数组中
- excel - VBA 使用 Excel 2013 不使用 M365 桌面应用程序
- php - WordPress 如何在 WordPress 中获取所有自定义和默认的帖子类型 slug
- typescript - 在 vs 代码的屏幕上没有显示 TypeScript 错误
- sass - scss 每个带有列表的循环 - SassError: $color: XX,XX,XX is not a color