Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore ConnectionState is in Waiting state forever in flutter app

I am trying to fetch records from the Firestore database and show it in the Flutter app.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text('Hello'),
          actions: <Widget>[
            IconButton(icon: Icon(Icons.list), onPressed: _pushSaved)
          ]),
      drawer: _buildDrawer(),
      body: _buildCarpoolsList(),
    );
  }

Widget _buildCarpoolsList() {
    return StreamBuilder<QuerySnapshot>(
        stream: Firestore.instance.collection("carpools").snapshots(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return CircularProgressIndicator();
          } else {
            var _carpools = snapshot.data.documents;
            return ListView(
                padding: const EdgeInsets.all(16.0),
                children: _deserializeCarpools(_carpools));
          }
        });
  }

In the _buildCarpoolsList() function the snapshot.ConnectionState is always ConnectionState.waiting, and the function returns CircularProgressBar(). ConnectionState.waiting

I have got a collection carpools in the FireStore database with a few records in it.

I have set the firestore database rules to allow all.

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

Edit: My Firebase authentication works. (If that helps)

What could be missing here?

like image 545
Pratik Avatar asked Sep 01 '19 07:09

Pratik


Video Answer


1 Answers

You may revise security settings in Firebase console. If you created the database in production mode (not testing), it comes with security rules that might block any connection until you allow so.

Open the Rules tab in the database screen, (JUST TO TEST -> Make allow read, write; as below ) If it works, just consider reading about the security rules and set it appropriately as per your needs.

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}
like image 186
MSaudi Avatar answered Sep 28 '22 11:09

MSaudi