如何使用Flutter从Firestore中的集合中获取特定文档 [英] how to obtain a particular document from a collection in firestore using Flutter

查看:76
本文介绍了如何使用Flutter从Firestore中的集合中获取特定文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对dart还是陌生的,所以显然是扑打...我确实集成了firestore并在android java中进行了编程..因此,我发现很难理解什么在android java和flutter中意味着什么到Firestore.

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.

例如在flutter中,addOnCompleteListener(android java)的替代方案是什么?

e.g. 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");
              }

考虑 users 集合有一个名为 John 的文档,其数据作为电子邮件:"j@gmail.com".

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()和listen()函数可能非常有帮助. 希望能有所帮助.

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

这篇关于如何使用Flutter从Firestore中的集合中获取特定文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆