【问题标题】:firebase auth keeps throwing an PLatformException on Vscode even I handle exceptions with try - catch即使我使用 try-catch 处理异常,firebase auth 仍会在 Vscode 上抛出 PLatformException
【发布时间】:2022-10-14 02:17:47
【问题描述】:

我正在使用 firebase_auth 的 signInWithEmailAndPassword 方法经历一个奇怪的行为

如果抛出错误,try catch 块应该捕获但 PLatformException 在编辑器中向上流动,就像我调用正常的 async/await 方法而没有捕获错误一样:

奇怪的是我已经在以前的项目中使用了相同的代码并且它工作正常,我做了相同的配置,并且它在正确的身份验证数据下工作正常,只是如果有错误它不会捕获它 我的代码:

  Future handleLoginProcess(BuildContext context) async {

_handleInputsCases();
_startLoading();
try {
  await FirebaseAuth.instance.signInWithEmailAndPassword(
      email: "barry.allen@example.com", password: "SuperSecretPassword!");
} on FirebaseAuthException catch (e) {
  print('Failed with error code: ${e.code}');
  print(e.message);
}
_endLoading();

}

抛出的错误似乎引导我这样做:

if (errorCode is String && (errorMessage == null || errorMessage is String) && !buffer.hasRemaining) {
  throw PlatformException(code: errorCode, message: errorMessage as String?, details: errorDetails, stacktrace: errorStacktrace);
} else {
  throw const FormatException('Invalid envelope');
}

我遗漏了一些东西,这可能是什么原因,它与vscode有关吗?

请与我分享您的想法,谢谢

【问题讨论】:

  • 什么是错误日志

标签: flutter firebase dart firebase-authentication


【解决方案1】:

如果此代码在您的另一个项目中运行良好。那么你应该检查两个项目的 SDK 版本。您可以在 YAML 文件中找到 SDK 版本。

【讨论】:

    【解决方案2】:

    在 pubspec.yaml

    firebase_auth: ^3.11.2
    

    代码

        Future loginWithUserEmail({@required String email, @required String password}) async{
        try{
          var userCredential = await _firebaseAuth.signInWithEmailAndPassword(
              email: email,
              password: password
          );
          //await _populateCurrentUser(userCredential.user);
          return userCredential.user != null;
        }catch(error){
          return error.toString();
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 2011-04-01
      • 2013-05-03
      • 2019-06-29
      相关资源
      最近更新 更多