Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Extracting info from QuerySnapshot variable in flutter app

Posted on November 11, 2022 By

Solution 1 :

 List<Map<String, dynamic>> list = 
  q.documents.map((DocumentSnapshot doc){
  return doc.data;
}).toList();

print(list);

Solution 2 :

Though the answer is right the current firebase API has changed drastically now to access QuerySnapshot one can follow the below code.

FirebaseFirestore.instance
.collection('users')
.get()
.then((QuerySnapshot querySnapshot) => {
    querySnapshot.docs.forEach((doc) {
        print(doc["first_name"]);
    });
});

And if you are using async/await then first you need to resolve the AsyncSnapshot and then work on it. If you like:

    return FutureBuilder(
    future: PropertyService(uid:userId).getUserProperties(),
    builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
      if (snapshot.hasError) {
        return Text("Something went wrong");
      }

      if (snapshot.connectionState == ConnectionState.done) {

        snapshot.data.docs.forEach((element) {
          Property property = Property.fromJson(element.data());
        });
        return Text("Demo Text");

      }

      return LoadingPage();
    }
);

taken from url

Solution 3 :

//But I am not getting all the documents present in my firestore DB collection. The first 10 or so entries are getting printed in the console. //

I think that is standard behavior. If you have one million records it can’t print everything in console. To check any particular set of documents you have to filter through where condition in query.

Solution 4 :

If you have still this problem, I hope this will help you.

This is how I get data from QuerySnapshot:

QuerySnapshot snapshot =
    await userCollection.where("uid", isEqualTo: uid).get();

List<Object?> data = snapshot.docs.map((e) {
    return e.data();
}).toList();

Map<dynamic, dynamic> userData = data[0] as Map;

print(userData["email"]);

Or you can easily get data by:

QuerySnapshot querySnapshot =
    await userCollection.where("uid", isEqualTo: uid).get();
print(querySnapshot.docs[0)['fieldName']);

Problem :

This code is running fine with futurebuilder and i m getting a listview properly.
But i want to see into the documents n print the details in console. I m not getting any idea about how to do this with QuerySnapshot variable.

Future getP() async {
  var firestore = Firestore.instance;
  var q = await firestore.collection('place_list').getDocuments();
  print(q.documents);
  return q.documents;
}

I think I have to call it n wait for the responses then print them, can anyone guide me how to do it?

READ  [FIXED] android - Combining multiple Firebase callbacks with RxJava2
Powered by Inline Related Posts

This is the co

This is what i am getting when i try to print the values to console

Comments

Comment posted by Henok

have you tried q.documents.toString()? let me know if it works i will post it as an anwer

Comment posted by IROC

Yes, I tried it…it is printing same thing as string instead of list/array… @Henok

Comment posted by IROC

Yes, it is working fine. But I am not getting all the documents present in my firestore db collection. First 10 or so entries are getting printed in console. But I am getting all 300 entries in

Comment posted by Henok

@IROC I am glad it’s working, that’s for another question. Post another question about not getting the whole data and comment the link here I will try to help there.

Comment posted by stackoverflow.com/questions/60411928/…

stackoverflow.com/questions/60411928/…

Android Tags:android, dart, flutter

Post navigation

Previous Post: [FIXED] android – How to pass data by Back Button, Kotlin
Next Post: [FIXED] Project with external module issue in android studio 3.6

Related Posts

[FIXED] android – W/System.err: java.lang.IllegalStateException: Fragment xxxxx not attached to a context Android
[FIXED] android – Google Play games, ‘Saved games’ deprecated? Android
[FIXED] android studio – Recyclerview animation not working in activity Android
[FIXED] java – Lag when switching tabs in BottomNavigationView Android
[FIXED] android – How to combine loop result in dart Android
[FIXED] java – How to List all Internal Storage Folders in Android Q (API Level 29)? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme