如何解决 [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] 未处理的异常

时间:2021-07-11 14:51:16

标签: flutter

我收到关于 [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] 未处理异常的错误:异常:登录失败。有谁知道如何解决这个问题?提前致谢

这是我的代码:

    Future<dynamic> loginWithGoogle() async {
        try {
          _authProvider = AuthProvider.Google;
    
          GoogleSignInAccount user = await _googleSignIn.signIn();
          GoogleSignInAuthentication googleSignInAuthentication =
              await user.authentication;
     
          loginWithMediaSocial(googleSignInAuthentication.accessToken)
              .then((value) {
            if (value['errorCode']== 500) {
              String error = "Login failed.";
              throw Exception (error);
            }
          });
        } catch (e) {
          print(e);
        }
      }

2 个答案:

答案 0 :(得分:0)

您是否遵循了 firebase 文档?我认为为了使用 Google 登录,您应该按照 firebase 文档中提到的步骤操作,并在使用 Google 登录之前添加文件 googleservices.json。

答案 1 :(得分:0)

如果您无法使用身份验证,请尝试以下步骤。

以下解决方案适用于 flutter 项目:

 Step 1: Generate SHA1 and SHA256 keys. 
 Step 2: Add both the SHA1 and SHA256 to firebase. (in you app settings)
 Step 3: Download google-services.json to android/app in your project folder.
 Step 4: In your terminal run the command flutter clean .
 Step 5: Run your flutter app.

有关更多信息,请访问: https://developers.google.com/android/guides/client-auth https://firebase.google.com/docs/flutter/setup