google登录失败/ PlatformException(PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,null))

时间:2020-10-13 21:07:20

标签: android flutter firebase-authentication google-signin

已成功打开凭据对话框(Google表单),但是在我填写凭据之后。

当我使用Google和Firebase实施登录时,出现以下错误消息。

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

这是调用API的按钮。

  Widget _buildSocialBtnRow() {
    AuthNotifier authNotifier = Provider.of<AuthNotifier>(context, listen: false);
    return OutlineButton(
      splashColor: Colors.white,
      color: Colors.white,
      onPressed: () => googleSignIn(_user, authNotifier),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
      highlightElevation: 0,
      borderSide: BorderSide(color: Colors.white),
      child: Padding(
      padding: const EdgeInsets.fromLTRB(0, 5, 0, 5),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
//        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
//          _buildSocialBtn(
//            () => print('Login with Facebook'),
//            AssetImage(
//              'lib/assets/facebook.png',
//            ),
//          ),
          _buildSocialBtn(
            () => print('Login with Google'),
            AssetImage(
              'lib/assets/google.jpg',
            ),
          ),
            Padding(
              
              padding: const EdgeInsets.only(left: 10),
              child: Text(
                'Sign in with Google',
                style: TextStyle(
                  fontFamily: 'Eletanco',fontSize: 18, color: Colors.white
                ),
              ),
            ),
        ],
      ),
    ),);
  }

我认为问题出在authResult无法正确调用signIn。

googleSignIn(User user, AuthNotifier authNotifier) async {
  GoogleSignInAccount googleSignInAccount = await gooleSignIn.signIn();

  if (googleSignInAccount != null) {
    GoogleSignInAuthentication googleSignInAuthentication =
        await googleSignInAccount.authentication;

    AuthCredential credential = GoogleAuthProvider.getCredential(
        idToken: googleSignInAuthentication.idToken,
        accessToken: googleSignInAuthentication.accessToken);

    AuthResult authResult = await auth.signInWithCredential(credential);

    FirebaseUser user = await auth.currentUser();
    print(user.uid);

    return Future.value(true);
  }
}

0 个答案:

没有答案