I am a beginner in app development and am having trouble with this error. The error I get is "error: A value of type 'User?' can't be assigned to a variable of type 'User'."
My Code:
Future signUpWithEmailAndPassword( String email, String password) async {
try {
UserCredential result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
User user = result.user;
return _userFromFirebaseUser(user);
} catch(e){
print(e.toString());
return null;
}
}
change the line
User user = result.user;
to
User? user = result.user;
You can actually fix that error by using !
. But make sure that result.user
is not null!
User user = result.user!;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With