这是我的 FirebaseAuthService 类中的电子邮件登录方法:
@override
Future<UserCustom> signInWithEmail(
String emailAddress, String password) async {
try {
UserCredential _signInWithEmailAndPasswordGoogle = await _auth
.signInWithEmailAndPassword(email: emailAddress, password: password);
if (_signInWithEmailAndPasswordGoogle.user != null) {
return _userToUserModel(_signInWithEmailAndPasswordGoogle.user);
} else {
throw PlatformException(
code: 'SIGN_IN_INTERRUPTED', message: 'Sin in interrupted');
}
} on PlatformException {
print('Happened');
rethrow;
}
}
这是应该处理异常的地方:
// creating the submit function
Future<void> _submit(EmailSignInModelProviderPattern model) async {
// if it is on sign in use sign in function ELSE use register function
try {
await model.submit();
Navigator.pop(context);
} on PlatformException catch (e) {
CustomErrorPlatformException(
title: 'Sign in failed',
exception: e,
).show(context);
} catch(e){
print(e.toString());
}
}
And yet when I enter a badly formatted address the process is interrupted at message_codecs.dart
file at the method dynamic decodeEnvelope(ByteData envelope){...
line 572 with error message:
发生异常。平台异常
(平台异常(firebase_auth,
com.google.firebase.auth.FirebaseAuthInvalidCredentialsException:
电子邮件地址格式错误。, {code: invalid-email,
附加数据:{},消息:电子邮件地址格式错误。}))
我不知道如何处理这个异常,因为我知道在升级到 firebase_auth 之前它从未发生在我身上:^0.18.0+1
.
检查这个问题,它解释了为什么会发生https://github.com/FirebaseExtended/flutterfire/issues/1760 https://github.com/FirebaseExtended/flutterfire/issues/1760
。
如果您使用模拟器并使用选项卡按钮更改文本字段,则该电子邮件字段上会留下额外的空格 ->*[电子邮件受保护] /cdn-cgi/l/email-protection *
为了避免这个额外的空间,你必须使用.trim()
method.
在你的情况下
UserCredential _signInWithEmailAndPasswordGoogle = await _auth
.signInWithEmailAndPassword(email: emailAddress.trim(), password: password);
我想这可以解决你的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)