我正在尝试在我的 flutter 应用程序中使用 Google 的 Firebase 身份验证。但是,在处理用户登录时,我似乎找不到一个“代码”来区分我要处理的异常类型。
Loginhandler.dart:
class LoginHandler {
String signup(_username, _password) async {
bool _valid = false;
final prefs = await SharedPreferences.getInstance();
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _username, password: _password)
.catchError((e) {
print(e);
print(e.message);
print(e.code);
print(e.details);
});
...
错误输出:
W/BiChannelGoogleApi(26738): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@4e727e7
W/IInputConnectionWrapper(26738): getCursorCapsMode on inactive InputConnection
I/flutter (26738): PlatformException(exception, The email address is already in use by another account., null)
I/flutter (26738): The email address is already in use by another account.
I/flutter (26738): exception
I/flutter (26738): null
I/flutter (26738): PlatformException(exception, The given password is invalid. [ Password should be at least 6 characters ], null)
I/flutter (26738): The given password is invalid. [ Password should be at least 6 characters ]
I/flutter (26738): exception
I/flutter (26738): null
我关注了this突出显示我可以使用 switch 语句的堆栈溢出线程,但上述错误输出没有可供我使用的错误“代码”。
最佳答案
我可以在 Android 上访问错误的“代码”属性。
try {
// login logic
} catch (e) {
print('Error: $e');
setState(() {
_isLoading = false;
if (_isIos) {
_errorMessage = e.details;
} else
_errorMessage = e.message;
print(e.code); // can access the code here
});
}
关于dart - Flutter:无法从 Firebase 身份验证中获取错误代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51009327/