gpt4 book ai didi

firebase - 如何使用 flutter 从 firebase 数据库中获取基于 userid 的值

转载 作者:IT王子 更新时间:2023-10-29 07:06:31 25 4
gpt4 key购买 nike

我尝试用 flutter 体验 Firebase Live 数据库。我想根据 userid 从 firebase 数据库中获取值。这意味着如果用户使用邮件登录,他需要根据他的用户 ID 查看他的详细信息。谁能帮我解决这些问题。

最佳答案

如果你有这个数据库:

users
userId
mail: userx@gmail.com
name: userx

然后要根据 userId 获取数据,请尝试以下操作:

 final FirebaseDatabase database = new FirebaseDatabase(app: widget.app);
_messagesRef = database.reference().child('users');

_messageRef.orderByKey().equalTo(userId).once().then((DataSnapshot snapshot) {
print('Connected to the database and read ${snapshot.value}');
});

首先配置数据库,然后引用位置,使用查询orderByKey()就可以根据提供的userId获取数据。

检查这里的例子:

https://github.com/flutter/plugins/blob/master/packages/firebase_database/example/lib/main.dart#L60

关于firebase - 如何使用 flutter 从 firebase 数据库中获取基于 userid 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51533743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com