Flutter DocumentSnapshot [英] Flutter DocumentSnapshot

查看:123
本文介绍了Flutter DocumentSnapshot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从firebase的DocumentSnapshot中获取数据。

I am trying to get the data from a DocumentSnapshot from firebase.

Firestore.instance.collection('products').document("Lucius_Malfoys_Zauberstab").get().then((DocumentSnapshot ds) {
          print(ds.exists);
        });

此方法可以正常工作并返回true,但是:

This method works totally fine and returns true, but:

      var keys =  ["Lucius_Malfoys_Zauberstab"];


     String id =  keys[0];
     print(id); ---> prints Lucius_Malfoys_Zauberstab


     Firestore.instance.collection('products').document(id).get().then((DocumentSnapshot ds) {
      print(ds.exists);
      });

返回假...

有任何人都有一个主意,为什么会这样呢?
这只是我的应用程序中的一个小问题,但是我很好奇为什么会这样。只是为了理解。谢谢!

Does anyone have an idea, why this is the case? It is just a small problem in my application, but I am curious why this happens. Just for understanding. Thank you!

编辑:

这是购物车集合的屏幕截图:

Here is a screenshot of the cart collection:

以下是产品的屏幕截图集合:

Here is a screenshot of the products collection:

推荐答案

我无法重现该问题。此时,我能做的最好的事情就是向您展示我的工作:

I can't reproduce the problem. The best I can do at this point is show you what I've done:

false 的第一次打印是在获得文档之前。然后,我创建了文档,再次运行 _test ,并打印了 true

The first print of false is before I had the document. I then created the document, ran _test again, and it printed true.

如果我取消对 / 55652643 / {document} 的许可,则 print 语句为'达到了t,相反,我得到了堆栈跟踪,表明该权限已被拒绝。

If I remove my permission on /55652643/{document}, the print statement isn't reached, and instead I get a stack trace that permission has been denied.

这篇关于Flutter DocumentSnapshot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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