alex jasper
alex jasper

Reputation: 73

Error: A value of type 'AuthResult' can't be assigned to a variable of type 'FirebaseUser'

I am working on a chat app and want to allow users to register using email and password. For some reason, I am getting the error below - is this implementation incorrect? I am not sure why i am getting "Error: A value of type 'AuthResult' can't be assigned to a variable of type 'FirebaseUser'."

class _RegistrationState extends State<Registration> {
  String email;
  String password;

  final FirebaseAuth _auth = FirebaseAuth.instance;

  Future<void> registerUser() async {
    FirebaseUser user = await _auth.createUserWithEmailAndPassword(
        email: email,
        password: password,
    );

Upvotes: 0

Views: 101

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80944

createUserWithEmailAndPassword returns Future<AuthResult>, you can check here:

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_auth/lib/src/firebase_auth.dart#L91

To solve the issue do the following:

final FirebaseUser user = (await _auth.createUserWithEmailAndPassword(
      email: email,
      password: password,
    ))
        .user;

add the field user which is of type FirebaseUser

Upvotes: 1

Related Questions