0

I am trying to use Uuid.v4 but when im fetching the data it come back as null. I found out that to fetch the docs id I need to generate id's like : bIEUVI7MQtfWFJYU99yO is there any way to generate id like this from flutter?

1 Answer 1

7

Just create a reference of an empty document like this, it will generate automatically your document ID:

final documentReference = FirebaseFirestore.instance.collection('collectionName').doc();

final docId = documentReference.id;
2
  • 4
    Note that you can use any collection ID, e.g. FirebaseFirestore.instance.collection('_').doc();. The generated doc ID isn't linked to any specific collection. Commented Apr 30, 2021 at 12:26
  • 2
    Didn't knew this one @RenaudTarnec thanks for mentioning it Commented Apr 30, 2021 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.