简体   繁体   中英

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

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.

eg whats the alternative to addOnCompleteListener(android java) in flutter?

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: "j@gmail.com".

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM