如何从扑朔迷离的实时数据库中获取名称和电话号码?
我的数据库中有一个用户:
Users {
userId: Xx1j9Pih4BPnu01vnFdMfZqGOr02: {name: 'jack5' ,phone: '0845204281'
}
}
到目前为止,我拥有以下功能,可以从实时Firebase数据库中获取数据。
static Future<dynamic> getCurrentUserInfo() async {
String? userId = FirebaseAuth.instance.currentUser?.uid;
final ref = FirebaseDatabase.instance.ref();
final snapshot = await ref.child('users/$userId').get();
if (snapshot.exists) {
return snapshot.value;
} else {
print('No data available.');
return '';
}
该功能返回对象。如何将此对象转换为字符串?或者:如何仅获取数据库当前用户的名称?
I have one user in my database:
Users {
userId: Xx1j9Pih4BPnu01vnFdMfZqGOr02: {name: 'jack5' ,phone: '0845204281'
}
}
So far I have the following function for getting data from the realtime firebase database.
static Future<dynamic> getCurrentUserInfo() async {
String? userId = FirebaseAuth.instance.currentUser?.uid;
final ref = FirebaseDatabase.instance.ref();
final snapshot = await ref.child('users/$userId').get();
if (snapshot.exists) {
return snapshot.value;
} else {
print('No data available.');
return '';
}
The function returns an object. How do I convert this object into a string? Or: How do I simply get the name of the current user of my database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想获取用户的
name
属性,假设您的用户是由UID存储的,那将是:If you just want to get the
name
property of the user, assuming your users are stored by their UID, that'd be: