【发布时间】:2020-10-30 15:56:22
【问题描述】:
我正在调整我的应用程序,并添加了一个“全名”字段以存储在 firebase 中并显示在用户个人资料页面上。我在注册新用户时收到错误“PlatformException(ERROR_INVALID_EMAIL,电子邮件地址格式错误。,null)”。从其他类似的帖子中,我找不到任何让我遇到障碍的命名约定。
注册.dart:
SizedBox(height: 20.0),
TextFormField(
decoration:
textInputDecoration.copyWith(hintText: 'Full Name'),
validator: (val) =>
val.isEmpty ? 'Enter a Full Name' : null,
onChanged: (val) {
setState(() => fullname = val);
}),
SizedBox(height: 20.0),
TextFormField(
decoration:
textInputDecoration.copyWith(hintText: 'Email'),
validator: (val) =>
val.isEmpty ? 'Enter an email' : null,
onChanged: (val) {
setState(() => email = val);
}),
SizedBox(height: 20.0),
TextFormField(
decoration:
textInputDecoration.copyWith(hintText: 'Password'),
obscureText: true,
validator: (val) => val.length < 6
? 'Enter a password 6+ chars long'
: null,
onChanged: (val) {
setState(() => password = val);
}),
SizedBox(height: 20.0),
RaisedButton(
color: Colors.blue[400],
child: Text(
'Register',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
if (_formKey.currentState.validate()) {
setState(() => loading = true);
dynamic result =
await _auth.registerWithEmailAndPassword(
fullname, email, password);
if (result == null) {
setState(() {
error = 'please supply a valid email';
loading = false;
});
}
}
}),
auth.dart
Future registerWithEmailAndPassword(String email, String password, String fullname) async {
try {
AuthResult result = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
FirebaseUser user = result.user;
return _userFromFirebaseUser(user);
} catch (e) {
print(e.toString());
return null;
}
}
【问题讨论】:
标签: firebase flutter authentication dart google-cloud-firestore