I have following code which does not work somehow:
Future<void> createUserWithEmailAndPassword() async {
//try nutzer erstellen
try {
UserCredential userCredential =
await Auth().createUserWithEmailAndPassword(
email: _controllerEmail.text,
password: _controllerPassword.text
);
}
catch (e) {
if (e is FirebaseAuthException) {
setState(() {
errorMessage = e.message;
});
}
}
}
I want to add the userCredential variable so I can use it later on but somehow it give me the following error:
This expression has a type of ‘void’ so its value can’t be used.
Try checking to see if you’re using the correct API; there might be a function or call that returns void you didn’t expect. Also check type parameters and variables which might also be void.dartuse_of_void_result
I want to use the userCredential variable so I can create in Cloud Firestore additional information for a user in a document.
Any ideas on how to solve?
2
Answers
The function createUserWithEmailAndPassword returns indeed a Future containing the UserCredential.
Please make sure that the return type of the function used in the Auth class matches the return type of the function createUserWithEmailAndPassword provided by FirebaseAuth.
It should look like this:
instead of using
try using