signUpWithEmail method

Future<void> signUpWithEmail(
  1. {required String email,
  2. required String password,
  3. required BuildContext context}
)

Signs up a user with email and password.

Parameters:

  • email: The email address of the user.
  • password: The password for the user.
  • context: The build context associated with the current widget tree.

Throws a FirebaseAuthException if the sign-up process fails. Displays an error message using the showSnackBar function in case of failure.

Implementation

Future<void> signUpWithEmail({
  required String email,
  required String password,
  required BuildContext context,
}) async {
  try {
    await _auth.createUserWithEmailAndPassword(
      email: email,
      password: password,
    );
  } on FirebaseAuthException catch (e) {
    // if you want to display your own custom error message
    if (e.code == 'weak-password') {
      print('The password provided is too weak.');
    } else if (e.code == 'email-already-in-use') {
      print('The account already exists for that email.');
    }
    showSnackBar(
        context, e.message!); // Displaying the usual firebase error message
  }
}