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()
.
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?
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With