Ampeire Richard
Ampeire Richard

Reputation: 33

my flutter code displays shows this error. "A value of type 'User?' can't be assigned to a variable of type 'User'."

I am running my dart code embedded with firebase but it shows the above error. What could be the problem?

Upvotes: 0

Views: 47

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63549

.createUserWithEmailAndPassword return nullable User.

You can make it nullable like like

final UserCredential credential =
    await _auth.signInWithEmailAndPassword(email: "", password: "");

final User? user = credential.user;

if (user != null) {
} else {
  //failed
}

More about /understanding-null-safety

Upvotes: 1

Related Questions