Home > Enterprise >  Document from firebase gets cut after some data
Document from firebase gets cut after some data

Time:11-25

I have tried to retrieve document from firestore in my flutter application. Below are screenshots of the data I am retrieving. enter image description here enter image description here enter image description here

This is the code I am using

FirebaseFirestore.instance.collection('schemes').doc("2VfjbKGY60ZE0HVz6dLz").get()
                              .then((DocumentSnapshot<Map<String,dynamic>> documentSnapshot) {
                            if (documentSnapshot.exists) {
                              print(documentSnapshot.data());
                              //print(documentSnapshot.data()!['name ']);
                            }
                          });

I am getting output which looks like this: enter image description here

I want to get the whole document from firebase and retrieve some fields from them. How should I do that?

CodePudding user response:

Try this:

FirebaseFirestore.instance.collection('schemes').doc("2VfjbKGY60ZE0HVz6dLz").get()
    .then((DocumentSnapshot doc) {
  if (doc.exists) {
     var title=doc['longDescriptions'];
     List benefits=doc['benefits'];
     //....rest of document fields
  }
});

You should include your statement in a Future async/await function and call it in initState function or use it in a FutureBuilder widget if you want to listen to document only once or StreamBuilder widget for continous listening for anychanges.

  • Related