firebase - Flutter Firebase 我将如何从快照中获取特定数据
问题描述
我目前正在为我的应用程序使用实时数据库。我无法从快照中读取特定用户数据。
我的代码:
final databaseReference = FirebaseDatabase.instance.reference();
void getData() {
databaseReference.once().then((DataSnapshot snapshot) {
Map<dynamic, dynamic> values = snapshot.value;
//print(snapshot.value['name']);
print('Data : ${snapshot.value}');
});
}
我的数据库布局:
Users:
userId:
name: TEST
email: TESTEmail@gmail.com
bio: TESTBio
我希望能够读取具有特定 userId 的个人的姓名(例如 Bdhsaiweuy2731319238121shda),我该怎么做?谢谢你的时间,我真的很感激。
解决方案
如果您知道他们的 UID,则可以直接查找该用户databaseReference.child("Users/Bdhsaiweuy2731319238121shda")
,然后从那里读取数据。就像是:
databaseReference.child("Users/Bdhsaiweuy2731319238121shda").once().then((DataSnapshot snapshot) {
print(snapshot.value['name']);
});
推荐阅读
- unity3d - 是否可以导航动画控制器的图形?
- angular - 获得 200 状态,但在角度 4 中使用 POST 时仍然出错
- c - 带有 `volatile` 数组的 `memcpy((void *)dest, src, n)` 安全吗?
- wordpress - ACF 和 Wordpress - 查找与帖子相关的所有帖子?
- python - Python 请求返回 503 响应
- kubernetes - 每个 Kubernetes pod 的唯一外部 IP
- javascript - 将一个单元格值拖放到一个由 PHP 生成的 html 表格中
- javascript - 使用 Angular 向文本添加动态样式
- video - FFMPEG 失败,只有两个输入帧
- python - pandas 通过采样读取 csv