Issue
I have been getting this error in futter while I was integrating firebase email,password sign up. "The getter uid
isn’t defined for the type ‘UserCredential’." not only for uid
but also for displayNmae
and email
. can anyone help me please?
void ValidateForm() async {
FormState? formState = _formkey.currentState;
Map value;
if (formState!.validate()) {
User user = await firebaseAuth.currentUser!;
if (user == null) {
firebaseAuth
.createUserWithEmailAndPassword(
email: _emailTextController.text,
password: _passwordTextController.text)
.then((user) => {
_userServices.createUser(
user.uid,
{
"username": user..displayName,
"email": user.email,
"userId": user.uid,
"gender": gender,
},
),
})
.catchError((err) => {print(err.toDtring())});
Navigator.pushReplacement(
(context), MaterialPageRoute(builder: (context) => a_n()));
}
}
}
Solution
Your user
value is a UserCredential
object, to get the uid
you need to access the user
inside that.
"userId": user.user.uid
Answered By – Huthaifa Muayyad
Answer Checked By – Gilberto Lyons (FlutterFixes Admin)