首页 > 解决方案 > Flutter google_sign_in package 登录问题,PlatformException

问题描述

当我尝试使用谷歌帐户登录时,我在终端中收到该错误:

PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

我的 pubspec.yaml 文件:

google_sign_in: ^4.5.6

我的代码:

import 'package:google_sign_in/google_sign_in.dart';

class androidLogInPage extends StatefulWidget {
  @override
  _androidLogInPageState createState() => _androidLogInPageState();
}

class _androidLogInPageState extends State<androidLogInPage> {
  bool _isLoggedIn = false;

  GoogleSignIn _googleSignIn = GoogleSignIn();
  Future _logIn() async {
    try {
      await _googleSignIn.signIn();
      setState(() {
        _isLoggedIn = true;
      });
    } catch (err) {
      print(err);
    }
  }

  _logOut() {
    _googleSignIn.signOut();
    setState(() {
      _isLoggedIn = false;
    });
  }

我已经有了 SHA-1 密钥,我该怎么办?我需要帮助。

标签: flutterauthenticationgoogle-signingoogle-account

解决方案


通常,当您添加使用原生 Android 或 iOS 代码的依赖项时,会出现平台异常。我认为您应该关闭应用程序并重新运行应用程序,它应该可以工作。这是因为它只重新加载 Flutter 代码而不是本机代码。


推荐阅读