I'm new to Flutter and really, really new to firebase.
I'm trying to create a user via the createUserWithEmailAndPasswordMethod. I've successfully created on, but I'm trying to improve it by allowing the user to enter the desired username and setting said username to the displayName attribute.
My code is as follows:
_createUser() async {
UserUpdateInfo updateInfo = UserUpdateInfo();
updateInfo.displayName = _usernameController.text;
FirebaseUser user = await _auth
.createUserWithEmailAndPassword(
email: _emailController.text,
password: _passwordController.text,
)
.then((user) {
user.updateProfile(updateInfo);
});
print('USERNAME IS: ${user.displayName}');
}
The problem is when I run the app it always throws this exception:
NoSuchMethodError: The getter 'displayName' was called on null.
Every time I debug the user variable keeps showing as null as well, even though the user is created and I can print the email and password!
I guess the problem is that Firebase user is null, but even if I move the print('USERNAME IS: ${user.displayName}'); to right after updateProfile the same happens.
Hope you guys can help! Thanks.