Well I am designing a sign up page and collecting some user datas such as phone number, name, surname, password etc. I want to add these infos to Firestore after user verifies e mail. User being created but the infos are not being added into Firestore. When I removed the if statement if (userCredential.user!.emailVerified == true)
and use only addUserDetails function it works perfectly. So my question is how can I check that state and write it into my code.
try {
final userCredential =
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _emailController.text.trim(),
password: _passwordController.text.toString(),
);
await userCredential.user?.updateDisplayName(
"${_firstNameController.text.toString()} ${_lastNameController.text.toString()}");
await userCredential.user?.updateEmail(_emailController.text.trim());
if (userCredential.user!.emailVerified == true) {
addUserDetails(
_firstNameController.text.trim(),
_lastNameController.text.trim(),
_emailController.text.toLowerCase(),
_phoneNumberController.text.trim(),
_passwordController.text.toString(),
FirebaseAuth.instance.currentUser!.uid.toString(),
);
}
}
Future addUserDetails(String firstName, String lastName, String eMail,
String phoneNumber, String password, String userID) async {
await FirebaseFirestore.instance
.collection("users")
.doc(FirebaseAuth.instance.currentUser!.uid)
.set({
"First Name": firstName,
"Last Name": lastName,
"E-mail": eMail,
"Phone Number": phoneNumber,
"Password": password,
"User ID": userID,
});
}