[英]Flutter Firebase : How to get a user's id by his username?
I'm actually working on a social app.我实际上正在开发一个社交应用程序。 I want to create a friend system and I'm struggling with the user search.
我想创建一个朋友系统,但我正在为用户搜索而苦苦挣扎。 I want the user to put the username of his friend in a TextField widget, query the Cloud Firestore (Firebase) database and get the friend's user profile if it exists.
我希望用户将他朋友的用户名放在 TextField 小部件中,查询 Cloud Firestore (Firebase) 数据库并获取朋友的用户个人资料(如果存在)。
The problem is, usernames are stored in "Users/USER_ID/profile/username" and I don't know how to query the database for this demand.问题是,用户名存储在“Users/USER_ID/profile/username”中,我不知道如何为这个需求查询数据库。
Here is the Cloud Firestore "path" i'm talking about: -这是我正在谈论的 Cloud Firestore“路径”:-
A little help would be welcome:)欢迎提供一点帮助:)
I tried this but this returns null
, probably because it is not searching in the right place.我试过了,但这返回
null
,可能是因为它没有在正确的位置搜索。
dynamic sUserFromUsername(String username) async {
try {
await FirebaseFirestore.instance
.collection('Users')
.where('username', isEqualTo: username)
.get()
.then((value) => value);
} catch (exception) {
print(exception);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.