0

I got this code to signup user with email and password in firebase. But the problem is that the try seems doesn't work. It keeps display an exception error message even when I have already put catch there.

static Future<FirebaseUser> signUp(String email, String password) async {
    try {
      AuthResult result = await _auth.createUserWithEmailAndPassword(
          email: email, password: password);
      FirebaseUser firebaseUser = result.user;

      return firebaseUser;
    } catch (e) {
      print(e.toString());
      return null;
    }
  }
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
Heri Kwok
  • 1
  • 2

1 Answers1

0

The error says your email is not properly formatted i.e. it's not matching the username@domain.tld format or is undefined. Try print(email) before the createUserWithEmailAndPassword function and check it.

Also adding an if statement helps:

if (["", null].contains(email)) {
  print("Email is null")
}

Validate email in dart might be useful but shouldn't be necessary as Firebase will throw an error is email is not valid.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • Yes, I actually have already tried using the email validator to solve that and it works in 1 part. But if I already input the right email format and non acceptable password format, it comes again with another exception. Well actually I try this code by following someone's tutorial video and it works fine with that kind of code. It's confusing me at all.. – Heri Kwok Jul 19 '21 at 15:59
  • @HeriKwok can you please print email and password and share it so we can see if anything is incorrect? – Dharmaraj Jul 19 '21 at 16:01