Flutter在尝试使用googleSingIn进行Firebase身份验证时无法捕获PlatformException

时间:2018-08-18 16:48:19

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

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

enter image description here

3 个答案:

答案 0 :(得分:2)

我最近也遇到了此错误,并且我发现在调试模式下(即单击VSCode中的my $href = { one => 1, word_counts => { "the" => { "dog" => 45, "cat" => 24, }, "train" => { "car" => 7, "wreck" => 37, } } }; my @keys = qw( word_counts train car ); my $temp = $href; foreach my $key ( @keys ) { die "Not a hash ref at <$key>" unless ref $temp eq ref {}; die "<$key> not in the hash" unless exists $temp->{$key}; $temp = $temp->{$key}; } print "Value is <$temp>"; # 7 按钮时)没有调用.catchError()回调。

但是,当您输入flutter run -d时,Run->Start Debugging方法将被回调,因为它不在调试模式下。

要获取您首选的模拟器代码,请将以下代码行粘贴到终端中:

.catchError()

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

instruments -s devices

将像以前一样调用xcrun simctl list 方法,并且其中的代码将按预期执行!

此外,该应用程序不会再因.catchError()而崩溃,而是会显示类似以下的日志:

PlatformException()

我也曾在Google登录中遇到过此问题,其中没有调用[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'uid' was called on null. Receiver: null

最后,如果您在处理Firebase身份验证时遇到一些错误,则应首先尝试首先通过终端运行。谢谢,希望对您有所帮助!

答案 1 :(得分:0)

答案 2 :(得分:0)

您可以使用Future Object来欺骗

通过示例,我想使用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为空

以及用户提交代码后在我代码中的某些位置使用此代码

FirebaseUser user = await _signInWithCode(code);

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