Flutter:取消Google 登录时闪退

461 阅读1分钟

最近在写flutter项目,其中涉及到了三方登录,facebook、google、appleId登录。其他两个登录在打包到蒲公英后都是可以正常运转,就是google登录,ios总是会出现问题。在点击取消的时候app直接闪退。本地开发点击取消是不会出现闪退的问题,在testflight中查看崩溃日志也没看出什么名堂来。

image.png

Future<UserCredential?> signInWithGoogle() async {
  // Trigger the authentication flow
  final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
  // Obtain the auth details from the request
  final GoogleSignInAuthentication? googleAuth = await googleUser?.authentication;
  // // Create a new credential
  
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth?.accessToken,
    idToken: googleAuth?.idToken,
  );
  // Once signed in, return the UserCredential
  return await FirebaseAuth.instance.signInWithCredential(credential);
}

代码是按照上面写的,猜测是在生产环境没拿到google用户信息或者google权限,在本地开发有缓存所以不会出现闪退的情况,反正也是盲改,我直接对googleAuth和googleUser进行判断操作,没想到瞎猫碰上死耗子,成了,哈哈哈哈哈哈哈哈哈哈。

if(googleUser == null || googleAuth == null) return null;

image.png

google登录是用插件google_sign_in实现的,直接按照文档上自述配置ios和安卓就没问题

image.png