StreamBuilder快照始终为ConnectionState.waiting [英] StreamBuilder snapshot is always ConnectionState.waiting

查看:89
本文介绍了StreamBuilder快照始终为ConnectionState.waiting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我了解StreamBuilders,但是我有些疑惑使我感到困惑。

I thought I understood StreamBuilders but I have some doubts that are puzzling me.

我以为ConnectionState.waiting意味着正在创建与流的连接因此仍无法接收流数据。
不过,就我而言,我总是收到ConnectionState.waiting。第一次使用的数据是initialData中指定的数据,这很好,但是如果ConnectionState始终是 waiting,则在我从流evnt获取值之后。
要在此处显示此内容,您可以看到第一次调用builder函数的屏幕截图。这看起来不错:快照值是initialData参数提供的值,并且ConnectionState正在等待

I thought that a ConnectionState.waiting means that the connection with the stream is being created so it is not still possible to receive stream data. Nevertheless in my case I am always receiving a ConnectionState.waiting . The first time the data is the data specified in the initialData, which is fine, but after i'm getting values from the stream evnt if the ConnectionState is always "waiting". To show this here you can see the screenshot of the first time the builder function is called. This looks good: the snapshot value is the one provided by the initialData parameter And the ConnectionState is waiting

这是第二次调用builder函数的屏幕截图。

Then this is the screenshot of the second time the builder function is called.

此处快照值是新的流值(因此连接状态现在应该处于活动状态)但实际上,connectionState仍在等待!

Here the snapshot value is a new stream value ( so the connection state should be active by now) BUT actually, the connectionState is still waiting!!


  1. 那我应该怎么解释呢?

  1. So how should I interpret that? How does that work?

即使connectionState始终在等待,为什么StreamBuilder仍继续接收快照?为什么它不处于活动状态?

Why does the StreamBuilder keep receiving snapshots even if the connectionState is always waiting? why it is not active?

我该如何调试?


推荐答案

这很可能是您的Firestore规则。如果是这样的话:

This is likely to be your Firestore rules. If it's like this:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}

那么您将没有经过身份验证即可获取数据。您可以通过允许任何人访问DB来快速(但不是永久地)进行测试...

then you'll have t be authenticated to grab the data. You can test this quickly (but not permanently) by allowing access to the DB from anyone ...

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

...但请务必将其更改为某些内容之后更安全。

... but please do change it to something more secure afterwards.

这篇关于StreamBuilder快照始终为ConnectionState.waiting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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