Reputation: 11
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());
}
Upvotes: 1
Views: 3450
Reputation: 67
change it to like this
(e.data() as dynamic)['myFieldOne']
https://i.sstatic.net/IhA7h.png
Upvotes: 0
Reputation: 1697
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
Upvotes: 1