skip to Main Content

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.

2

Answers


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

    Login or Signup to reply.
  2. 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'];
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search