Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

flutter - firestore document update data without id

I have snapshot of a firestore collection,

fireStoreInst.collection(widget.loggedInUser.uid)
             .doc('subjects')
             .collection(widget.deckName).snapshots()

and I want to update the data inside which according to Flatbutton click(hard/good/easy). when user click any of these 3 buttons I want to update the respective data to true and other 2 to false.

enter image description here

As I don't know the docID, I tried,

1.

widget.snapshot.data.docs[widget.cardIndex].updateData({
          widget.hardness: true,
          widget.remove1: false,
          widget.remove2: false
        });
  1. And for getting the DocumentID I tired,
docID: snapshot.data.docs[cardIndex].documentID
FirebaseFirestore.instance
            .collection('JWfsiG4VAQPpv3PNwP7E5dNbGEe2')
            .doc('subjects')
            .collection('Latest QA')
            .doc(widget.docID)
            .update({
          widget.hardness: true,
          widget.remove1: false,
          widget.remove2: false
        });

But all ended up in errors. most of them due to deprecated codes can anyone help me?

question from:https://stackoverflow.com/questions/65931776/firestore-document-update-data-without-id

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Problem solved:

docID: snapshot.data.docs[cardIndex].id

instead of

docID: snapshot.data.docs[cardIndex].documentID

documentID deprecated


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...