电子邮件地址格式错误 - Flutter firebase
The email address is badly formatted - Flutter firebase
FirebaseAuthException ([firebase_auth/invalid-email] The email address is badly formatted
当我使用 flutter firebase 电子邮件密码验证时,它显示电子邮件地址格式错误。当身份验证过程有任何问题时,姓名和车辆号码也会传递给数据库。为什么会发生。如果有人可以帮助我找出问题,请帮助我
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()));
}
}
在执行 SignUp 函数时(在 Material Button OnPressed 处),变量传递的顺序是否错误?
它几乎总是尾随空格,试试:
postDetailsToFirestore(
email.trim(),
role,
name,
vehicleNo,
),
或者您也可以尝试硬编码正确的电子邮件地址并检查问题是在逻辑上还是在UI。
您正在呼叫:
signUp(
emailController.text,
passwordController.text,
role,
vehicleNo.text,
name.text);
而signUp
定义为:
void signUp(String name, String email, String password, String role,
String vehicleNo) async {
因此两者的参数顺序不同,导致您使用 password
值作为电子邮件地址并使用 role
值作为密码来调用 Firebase。
要解决此问题,请按照 signUp
期望的相同顺序传递参数。
FirebaseAuthException ([firebase_auth/invalid-email] The email address is badly formatted
当我使用 flutter firebase 电子邮件密码验证时,它显示电子邮件地址格式错误。当身份验证过程有任何问题时,姓名和车辆号码也会传递给数据库。为什么会发生。如果有人可以帮助我找出问题,请帮助我
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()));
}
}
在执行 SignUp 函数时(在 Material Button OnPressed 处),变量传递的顺序是否错误?
它几乎总是尾随空格,试试:
postDetailsToFirestore(
email.trim(),
role,
name,
vehicleNo,
),
或者您也可以尝试硬编码正确的电子邮件地址并检查问题是在逻辑上还是在UI。
您正在呼叫:
signUp(
emailController.text,
passwordController.text,
role,
vehicleNo.text,
name.text);
而signUp
定义为:
void signUp(String name, String email, String password, String role,
String vehicleNo) async {
因此两者的参数顺序不同,导致您使用 password
值作为电子邮件地址并使用 role
值作为密码来调用 Firebase。
要解决此问题,请按照 signUp
期望的相同顺序传递参数。