0

I am trying to set my documentID manually in my flutter application but it keeps creating a new field inside my document named DocumentID. How do I set my documented?

 final barcode = TextEditingController(); final price = TextEditingController(); final stock = TextEditingController(); final color = TextEditingController(); ///the above are textformfield controllers I use for the data input addData() { Map<String, dynamic> theData = { //"DocumentID" : barcode.text, "Color" : color.text, "Price" : price.text, "Stock" : stock.text, }; CollectionReference collectionReference = Firestore.instance.collection("products"); collectionReference.add(theData); } addID(){ DocumentReference dataID = Firestore.instance.document("products"); dataID.set(DocumentReference, barcode.text); } 

The data also displays only "" in my database when using the method addData: enter image description here

Below is mu adjusted code:

 final barcode = TextEditingController(); final price = TextEditingController(); final stock = TextEditingController(); final color = TextEditingController(); addData() { Map<String, dynamic> theData = { "Color" : color.text, "Price" : price.text, "Stock" : stock.text, }; CollectionReference collectionReference = Firestore.instance.collection("products"); FirebaseFirestore.instance.collection("products").doc(barcode.text).set(theData); collectionReference.add(theData); } 

I get this error: enter image description here

1
  • its creating a documentid because you have this //"DocumentID" : barcode.text, probably wasn't commented Commented Nov 18, 2020 at 9:54

1 Answer 1

1

you can set it like this

 FirebaseFirestore.instance.collection("products").doc("my_own_document_id").set(data); 

you can set the document id while creating it, but you cannot change it

Sign up to request clarification or add additional context in comments.

3 Comments

Does the hintText/Labeltext interfere with anything?
How can I input barcode.text because its a textformfield so the page has to load first, maybe add await to the method?
format the question for the answer provided, ask new question on it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.