Reputation: 3
FirebaseAuthException ([firebase_auth/invalid-email] The email address is badly formatted
when I uses flutter firebase email password auth it shows email adress badly formated. name and vehicle number is also pass to the database when authentication process is there any problem in it. why it occurs. if someone can help me to find out the problem help me
MaterialButton(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20.0))),
elevation: 5.0,
height: 40,
onPressed: () {
setState(() {
showProgress = true;
});
signUp(
emailController.text,
passwordController.text,
role,
vehicleNo.text,
name.text);
},
child: Text(
"Register",
style: TextStyle(
fontSize: 20,
),
),
color: Colors.white,
)
],
),
],
),
),
),
),
),
],
),
),
);
}
void signUp(String name, String email, String password, String role,
String vehicleNo) async {
const CircularProgressIndicator();
if (_formkey.currentState!.validate()) {
await _auth
.createUserWithEmailAndPassword(
email: email.trim(), password: password.trim())
.then(
(value) => {
postDetailsToFirestore(
email,
role,
name,
vehicleNo,
),
},
)
.catchError((e) {
print("its an error");
});
}
}
postDetailsToFirestore(
String email, String role, String name, String vehicleNo) async {
FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance;
User? user = _auth.currentUser;
UserModel userModel = UserModel();
userModel.email = email;
userModel.name = name;
userModel.vehicleNo = vehicleNo;
userModel.uid = user!.uid;
userModel.role = role;
await firebaseFirestore
.collection("users")
.doc(user.uid)
.set(userModel.toMap());
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => LoginScreen()));
}
}
Upvotes: 0
Views: 1445
Reputation: 598901
You're calling:
signUp(
emailController.text,
passwordController.text,
role,
vehicleNo.text,
name.text);
And signUp
is defined as:
void signUp(String name, String email, String password, String role,
String vehicleNo) async {
So the order of the arguments is different between the two, leading you to call Firebase with the password
value as the email address and the role
value as the password.
To fix the problem, pass the arguments in the same order as signUp
expects them.
Upvotes: 1
Reputation: 766
It's almost always trailing whitespace, try:
postDetailsToFirestore(
email.trim(),
role,
name,
vehicleNo,
),
Alternatively you can also try to hardcode the right email address and check whether the problem is in logic or in UI.
Upvotes: 0
Reputation: 111
When executing the SignUp function (at Material Button OnPressed), are the variables passed in the wrong order?
Upvotes: 1