简体   繁体   English

Flutter Firebase:如何通过用户名获取用户ID?

[英]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.

相关问题 如何从Flutter中的Firebase Auth获取用户id? - How to get user id from Firebase Auth in Flutter? 如何从Flutter中的Firebase获取当前用户id - How to get the current user id from Firebase in Flutter 如何在 Firebase Analytics 中设置用户 ID 和属性 - Flutter - How to set user Id and propeties in Firebase Analytics - Flutter 如何使用 http POST 方法将当前用户(使用应用程序的人)Firebase Id 令牌从 Flutter 应用程序发送到 restapi? - How to send current user's(person using the app), Firebase Id token,from the Flutter app, to restapi, using http POST method? 如何在没有 firebase 身份验证的情况下获取用户 ID? - how to get the user ID without firebase authentication? 如何让创建的文件以与存储在flutter中的用户的email相匹配的名称保存? - How to get the created file to be saved with a name that matches the user's email stored in Firebase Storage in flutter? Firestore - 如何在删除他的帐户时从他自己创建的所有文档中删除用户 ID? - Firestore - how do I remove user's ID from all the documents he's created himself when deleting his account? firebase规则如何让用户只能读取他的数据 - firebase rules how to make user can read only his data 在android中获取firebase用户id - Get firebase user id in android 获取当前文档的 ID Flutter / Firebase - Get ID of current document Flutter / Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM