如何在Flutter/Dart中捕获platformException? [英] How to catch platformException in flutter/dart?

查看:1018
本文介绍了如何在Flutter/Dart中捕获platformException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到

发生异常. PlatformException(PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException:12501:,null))

Exception has occurred. PlatformException (PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException: 12501: , null))

每当我尝试取消登录并在我的应用程序中弹出Google时登录.

whenever I try to cancel login with google pop up in my app.

要复制:

在应用程序中,当按下Google登录按钮时,会显示google登录页面,其中包含所有gmail帐户供您选择以登录或注册.

In the app when pressed login with google button the google sign in page appears with all the gmail accounts to choose from to login or signup.

触摸弹出窗口的外部区域以取消登录,然后关闭弹出窗口.

Touch the outer area of the pop up to cancel the sign in , which then shuts down the pop up.

此后,代码中出现平台异常:

After that there is platform exception in the code saying :

发生异常. PlatformException(PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException:12501:,null))

Exception has occurred. PlatformException (PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException: 12501: , null))

现在登录按钮不起作用,应用程序崩溃了,

Now the login button is not working and the app crashes,

尝试尝试/捕获-不起作用

Tried try/catch - not working

推荐答案

try {
  final res = await _auth.signInWithEmailAndPassword(
      email: email, password: password);
  if (res != null) loggedUser = res.user;
} on PlatformException catch (err) {
  // Handle err
} catch (err) {
  // other types of Exceptions
}

这篇关于如何在Flutter/Dart中捕获platformException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆