【问题标题】:Flutter unable to catch PlatformException while attempting firebase auth with googleSingInFlutter 在尝试使用 googleSingIn 进行 Firebase 身份验证时无法捕获 PlatformException
【发布时间】:2019-01-25 09:40:48
【问题描述】:

我刚刚开始使用flutter,我正在尝试使用googleAuth实现firebase登录,它在下面显示了这些错误:

【问题讨论】:

标签: android firebase firebase-authentication flutter google-authentication


【解决方案1】:

我最近也遇到了这个错误,我发现.catchError() 回调没有在调试模式下被调用(当你点击 VSCode 中的Run->Start Debugging 按钮时)。

但是,当您输入 flutter run -d 时,.catchError() 方法会被回调,因为它未处于调试模式。

要获取您喜欢的模拟器的代码,请将这行代码粘贴到终端中:

instruments -s devices

如果这不起作用,您也可以尝试粘贴:

xcrun simctl list

.catchError() 方法将与以前不同地被调用,其中的代码将按预期执行!

此外,应用程序不会再因PlatformException() 而崩溃,而是您会得到这样的日志:

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'uid' was called on null.
Receiver: null

我在 Google 登录中也遇到过这个问题,其中 .catchError() 没有被调用!

总之,如果你在处理 Firebase Authentication 的错误时遇到了一些错误,你应该首先尝试通过终端运行。谢谢,我希望这会有所帮助!

【讨论】:

  • :) 很高兴这对您有所帮助
【解决方案2】:

【讨论】:

  • 那些解决方案没用!我已经实现了所有这些,但没有结果
  • 这是一个悬而未决的问题。
【解决方案3】:

你可以通过使用未来对象来做诡计

例如,我想使用 PhoneAuth 并检查用户编写的 代码 是否正确 所以问题是在用户输入错误代码

后无法捕捉到异常

试试这个代码 首先像这样声明异步方法

Future<FirebaseUser> _signInWithCode(String code) async {
    AuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(
        verificationId: verificationID, smsCode: code);
    try {
      AuthResult result = await mAuth.signInWithCredential(phoneAuthCredential);

      FirebaseUser currentUser = await mAuth.currentUser();
      if (currentUser != null && result.user.uid == currentUser.uid) {
        return currentUser;
      } else {
        return null;
      }
    } on PlatformException catch (exp) {}

    return null;
  }

所以如果抛出 exp,那么 come 的值为 null

在用户提交代码后在我的代码中的某些地方使用此代码

FirebaseUser user = await _signInWithCode(code);

if (user != null)
      debugPrint("true input code");
    else {
      debugPrint("WRONNNG input code");
      setState(() {
        isValidCode = false;
      });
    }

【讨论】:

    猜你喜欢
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 2021-04-14
    • 2020-12-04
    • 2020-12-26
    • 2018-05-22
    • 2020-12-12
    相关资源
    最近更新 更多