Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter Firestore – Instance of 'Future <dynamic>' Error

I have a code like this:

  name = FirebaseFirestore.instance.collection("users").doc("${FirebaseAuth.instance.currentUser?.uid}").get().then((value) => value.data()!["name"]).toString();

I get the following output from this code:

 Instance of 'Future <dynamic>'

How can I resolve this error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Thanks for help.

>Solution :

You have to add await to Future to get the returned value.

var snapshot = await FirebaseFirestore.instance.collection("users").doc("${FirebaseAuth.instance.currentUser?.uid}").get();

if(snapshot.data!=null){
name=snapshot.data!['name'];
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading