Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The getter 'documentID' isn't defined for the type 'DocumentReference'

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'],
    ));

I'm getting an error in line 8 in "documentID: documentSnapshot.reference.documentID," the Cloud Firestore version that I'm using is 0.16.0+1.

like image 791
Abdullah Hamadi Avatar asked Oct 26 '25 06:10

Abdullah Hamadi


1 Answers

See the API documentation for DocumentReference. The property you're looking for is called id. There is no property documentID in modern versions of the SDK.

like image 119
Doug Stevenson Avatar answered Oct 27 '25 22:10

Doug Stevenson