Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StreamBuilder snapshot is always ConnectionState.waiting

Tags:

flutter

dart

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

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 enter image description here

Then this is the screenshot of the second time the builder function is called. enter image description here

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. So how should I interpret that? How does that work?

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

  3. How can I debug that?

like image 777
onthemoon Avatar asked Apr 30 '19 11:04

onthemoon


1 Answers

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;
    }
  }
}

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.

like image 166
Lee Probert Avatar answered Oct 23 '22 11:10

Lee Probert