Skip to content

Instantly share code, notes, and snippets.

@aduquet
Created March 14, 2022 06:06
Show Gist options
  • Save aduquet/670dc94356354df4251f2a87e3b2936e to your computer and use it in GitHub Desktop.
Save aduquet/670dc94356354df4251f2a87e3b2936e to your computer and use it in GitHub Desktop.
Reading data from firebaseStore with flutter... SOLUTION! :)
I spend a lot of time trying to access a specific document from firebase DB with flutter.
This is some links that help me
https://stackoverflow.com/questions/53517382/query-a-single-document-from-firestore-in-flutter-cloud-firestore-plugin
https://stackoverflow.com/questions/67575893/the-method-cant-be-unconditionally-invoked-because-the-receiver-can-be-nu
https://stackoverflow.com/questions/69624553/flutter-error-the-operator-isnt-defined-for-the-class-object
I had this error as well
type '_JsonQuerySnapshot' is not a subtype of type 'Map<String, dynamic>' in type cast"
After 2 days looking for an anserw I got this, the solution...
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('YOU COLLECTION NAME')
.doc('xxxxxxx') //ID OF DOCUMENT
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return new CircularProgressIndicator();
}
final document = snapshot.data as DocumentSnapshot;
return Text(document['DESIRED FIELD OF YOUR DOCUMENT']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment