Home > Back-end >  Flutter Firestore - Instance of 'Future <dynamic>' Error
Flutter Firestore - Instance of 'Future <dynamic>' Error

Time:07-25

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?

enter image description here

Thanks for help.

CodePudding user response:

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'];
}

CodePudding user response:

The 'name' is already in a string, you don't need to use toString() Try removing that.

  • Related