0

I am trying to retrieve data from firestore and put the val in an if statement but when I did It gave me this error :

I/flutter ( 8492): Closure: () => String from Function 'toString':.

Here is my code:

void getUserData() async {
    try {
      firestoreInstance
          .collection('Users')
          .document(usernameController.text)
          .get()
          .then((value) {
        setState(() {
          email = (value.data)['email'];
          password = (value.data)['password'];
          gender = (value.data)['gender'];
          username = (value.data)['username'];
          userType = (value.data)['userType'];
        });
      });
    } catch (e) {
      print(e.toString);
    }
  }

forgot to mention that when I print userType which is a text It Give me NULL.

1 Answer 1

1

just remove your ()

void getUserData() async {
try {
  firestoreInstance
      .collection('Users')
      .document(usernameController.text)
      .get()
      .then((value) {
    setState(() {
      email = value.data['email'];
      password = value.data['password'];
      gender = value.data['gender'];
      username = value.data['username'];
      userType = value.data['userType'];
    });
  });
} catch (e) {
  print(e.toString);
}

}

or use like this

username = value['username'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.