【问题标题】:How to solve [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception如何解决 [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] 未处理异常
【发布时间】:2021-09-21 00:38:04
【问题描述】:

我收到有关 [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);
        }
      }

【问题讨论】:

  • 检查从哪里打印的异常。是在catch 吗?
  • 是的。在 catch 但得到错误 [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] 未处理的异常:异常:登录失败。

标签: flutter


【解决方案1】:

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

【讨论】:

  • 感谢您的回复。我没有使用火力基地
【解决方案2】:

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

以下解决方案适用于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

【讨论】:

  • 感谢您的回复。我没有使用火力基地。我收到的错误消息来自 loginWithMediaSocial()。之后,我想将错误返回给 main.dart
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-21
  • 2020-10-20
  • 1970-01-01
  • 2021-11-20
  • 2021-03-22
  • 2020-12-05
  • 1970-01-01
相关资源
最近更新 更多