I want to add data into the firestore database if the document ID doesn\'t already exists. What I\'ve tried so far:
// varuId == the ID that is set to the do
You can get() the document and use the exists property on the snapshot to check whether the document exists or not.
An example:
final snapShot = await Firestore.instance
.collection('posts')
.document(docId)
.get()
if (snapShot == null || !snapShot.exists) {
// Document with id == docId doesn't exist.
}