signup1 method
Implementation
Future signup1()async{
if (!validateSignupFields()) {
return;
}
//user does not exist
var result = await checkReferralCode(referralCodeTxtController.text);
if (!result) {
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Invalid Invitation Code",
duration: Duration(seconds: 10),
message:
"The invitation code you entered is invalid. Please try again.",
actions: [
FlashAction(
label: 'Contact Support',
onPressed: () {
launchEmail();
},
),
FlashAction(
label: 'Try Again',
),
],
);
return;
}
try {
openDialog(LoadingDialog());
UserCredential credential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: emailTxtController.text.trim(),
password: passTxtController.text);
credential.user?.updateDisplayName("${firstNameTxtController.text} ${lastNameTxtController.text}");
handleSignup();
}
on FirebaseAuthException catch (e) {
closeDialog();
switch (e.code) {
case 'email-already-in-use':
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: 'This email is already associated with an account.',
);
print('This email is already associated with an account.');
break;
case 'invalid-email':
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: 'The email address is badly formatted.',
);
print('The email address is badly formatted.');
break;
case 'operation-not-allowed':
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: 'An Error occurred. Please contact support',
);
print('Email/password accounts are not enabled. Please enable them in Firebase Console.');
break;
case 'weak-password':
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: 'Password is weak. Please try a stronger password',
);
break;
default:
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: 'An error occurred. Please contact support',
);
print('Firebase Auth Error: ${e.code} - ${e.message}');
}
} catch (e) {
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: 'An error occurred. Please contact support',
);
print('Unexpected error: $e');
}
}