The property 'uid' can't be unconditionally accessed because the receiver can be 'null'
1,963
User can be null. So do null checking first like
try {
FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: kEmail.text, password: kPassword.text)
.then((value) {
if(value!=null && value.user != null){
userCollection.doc(value.user.uid).set({
'userName': kUserName,
'email': kEmail,
'password': kPassword,
'uid': value.user.uid
});
}else{
throw Error();
}
});
} catch (err) {
print(err.toString);
}
or a simple sol will be
..
Rest of the code...
userCollection.doc(value.user!.uid)
....Rest of the code //Add ! after user
Author by
David Buck
Python/Django/AWS Software Engineer Computer Science and Data Analytics Masters Student R and Java Previously: VP Engineering Managing Director Mainframe DBA IT Manager Cobol/Adabas/Natural Developer
Updated on December 29, 2022Comments
-
David Buck over 1 year
User is not working. I'm not uploading a collection in Firebase
try { FirebaseAuth.instance.createUserWithEmailAndPassword (email: kEmail.text, password: kPassword.text) .then((value) { userCollection.doc(value.user.uid).set({ 'userName': kUserName, 'email': kEmail, 'password': kPassword, 'uid': value.user.uid }); }); } catch (err) { print(err.toString()); }
-
Javier A almost 3 yearsDid the answer by Problematic Dude answer your question?
-