【问题标题】:How to access details from a method in flutter in firestore如何从firestore中flutter中的方法访问详细信息
【发布时间】:2020-07-22 09:11:18
【问题描述】:

这些是上传到 Firestore 文档的详细信息。

'uid': this._userId,
'Email': this._email,
'Fullname': this._fullname,
'Location': this._location,
'ImageUrl': this._imageurl = await uploadImage(),

使用下面的代码 - 如果我是正确的 - 我正在尝试使用文档中的 uid 代码访问当前用户的详细信息。

final user = FirebaseAuth.instance.currentUser();

getData() async {
  return await Firestore.instance
      .collection('userdetails')
      .where('uid', isEqualTo: user)
      .getDocuments();
}

现在,由于该方法返回包含当前用户的用户详细信息的文档,我如何访问每个值以显示在 screen.Name 和图像 URL 上?

【问题讨论】:

  • DocumentReference docRef = await Firestore.instance .collection('userdetails') .add(userData) .catchError((e) { print(e); });这就是我如何将数据添加到 firestore 如何将其添加到当前 uid 的文档中。我应该在哪里包含 tha 在查询中

标签: firebase flutter dart google-cloud-firestore


【解决方案1】:

我不希望该代码能够工作,因为 userFirebaseUser 对象,而不是 UID 字符串。您可能希望改为使用当前用户的uid 来过滤结果:

Firestore.instance
    .collection('userdetails')
    .where('uid', isEqualTo: user.uid)
    .getDocuments();

【讨论】:

  • 好的,但是文档的详细信息进入这个getData()方法后如何访问它来显示
  • 这听起来像是一个完全不同的问题。您应该尝试一下,然后使用您正在使用的代码发布另一个问题,该代码无法按您预期的方式工作。
  • 我把它作为一个单独的问题做,如果你能理解,请检查它。
【解决方案2】:

以下是访问这些字段的方法:

Firestore.instance.collection('userdetails').document(user.uid).get().then((doc) {
    _fullname = doc.data['Fullname'];
    _imageUrl = doc.data['ImageUrl'];
}

【讨论】:

    猜你喜欢
    • 2021-05-10
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多