how to obtain a particular document from a collection in firestore using Flutter

6,103

Regarding your question about how to get the document from collection you can refer the following code

    DocumentReference documentReference =
                Firestore.instance.collection("users").document("John");
            documentReference.get().then((datasnapshot) {
              if (datasnapshot.exists) {
                print(datasnapshot.data['email'].toString(););
              }
              else{
                print("No such user");
              }

consider users collection has a document named as John with data as email: "[email protected]".

You can find the documentation very useful and almost all the functions are present for the flutter too. Just you should be able to do error and exception handling.

oncomplete() and listen() functions might be very helpful. Hope it helped.

Share:
6,103
Sabih Khan
Author by

Sabih Khan

Updated on December 08, 2022

Comments

  • Sabih Khan
    Sabih Khan over 1 year

    I am new to dart and so obviously to flutter... I did integrate firestore and did programming in android java.. and so I am finding it a little bit difficult to understand what means what in android java and flutter in regards to Firestore.

    e.g. whats the alternative to addOnCompleteListener(android java) in flutter?