【问题标题】:The getter 'documentID' isn't defined for the type 'DocumentReference'没有为“DocumentReference”类型定义获取器“documentID”
【发布时间】:2021-06-06 23:46:47
【问题描述】:
CollectionReference itemsReference =
    FirebaseFirestore.instance.collection('items');
itemsReference.snapshots().forEach((snapshot) {
  snapshot.docs.forEach((documentSnapshot) {
    products.add(new Product(
      name: documentSnapshot.data()['name'],
      price: double.parse("${documentSnapshot.data()['price']}"),
      documentId: documentSnapshot.reference.documentID,// The getter 'documentID' isn't defined for the type 'DocumentReference'.
      description: documentSnapshot.data()['description'],
      image: documentSnapshot.data()['image'],
      imageCount: documentSnapshot.data()['image_count'],
      sellerEmail: documentSnapshot.data()['seller'],
      category: documentSnapshot.data()['category'],
      location: documentSnapshot.data()['location'],
      verified: documentSnapshot.data()['verified'],
    ));

我在“documentID: documentSnapshot.reference.documentID”的第 8 行遇到错误,我使用的 Cloud Firestore 版本是 0.16.0+1。

【问题讨论】:

  • 使用 documentSnapshot.id 获取文档 ID

标签: flutter dart google-cloud-firestore


【解决方案1】:

请参阅DocumentReference 的 API 文档。您要查找的属性称为id。在现代版本的 SDK 中没有属性 documentID

【讨论】:

    猜你喜欢
    • 2021-10-12
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 2020-09-23
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多