Flutter Firebase.signInWithGoogle method not found

前端 未结 3 1218
星月不相逢
星月不相逢 2020-12-11 07:42

I am trying to add Google Authentication in my Flutter Application. But my Android studio is not able to find the method signInWithGoogle under Fire

3条回答
  •  星月不相逢
    2020-12-11 08:13

    Instead of using fireebaseauth.signInWithGoogle (which is depreciated)
    use:

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

    Your code will look like this:

    Future handleSign() async {
    preferences = await SharedPreferences.getInstance();
    setState(() {
      loading = true;
    });
    
    GoogleSignInAccount googleUser = await googleSignIn.signIn();
    GoogleSignInAuthentication googleSignInAuthentication = await googleUser
        .authentication;
    AuthCredential credential = GoogleAuthProvider.getCredential(
        idToken: googleSignInAuthentication.idToken,
        accessToken: googleSignInAuthentication.accessToken);
    }
    

提交回复
热议问题