Flutter Google Login not Getting Registered in Firebase (AndroidX)

by Philippe Fanaro   Last Updated October 18, 2019 01:26 AM - source

1. The Problem

I'm trying to implement simple Facebook and Google Sign-in buttons with Firebase and Flutter, however the Google version is acting very weird. When I print the FirebaseAuth.instance.currentUser() I either get errors or prior Facebook login data.

When I login with Facebook, my account does appear on Firebase, however, the Google login seems to do nothing.

Is this something I messed up in the code below or some incompatibility problem with AndroidX with parts of these libraries? Something else?

Also, it is not very clear to me if I have to put the Project public-facing name somewhere inside my project to make the integration with Firebase work (I had to do something similar to setup the Facebook Login button).

2. The Facebook Login

I had to replace logInWithReadPermissions with signInWithCredential because recent versions have changed their API. I've also tried to use previous versions of the packages, but encountered many errors (probably due to AndroidX):

final _auth = FirebaseAuth.instance;

Future<FirebaseUser> _loginWithFacebook () async {
  final facebookLogin = FacebookLogin();
  final result = await facebookLogin.logInWithReadPermissions(['email']);

  if (result.status == FacebookLoginStatus.loggedIn){
    final FacebookAccessToken accessToken = result.accessToken;
    AuthCredential credential = FacebookAuthProvider.getCredential(
      accessToken: accessToken.token,

    AuthResult signInResult = await _auth.signInWithCredential(credential);

    FirebaseUser fbUser = signInResult.user;
    return fbUser;
    return null;

3. The Google Login

Again, signInWithCredential seems to be the more recent API:

Future<FirebaseUser> _loginWithGoogle () async{
  final GoogleSignIn _googleSignIn = GoogleSignIn();

  GoogleSignInAccount googleUser = await _googleSignIn.signIn();

  final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
  final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  AuthResult signInResult = await _auth.signInWithCredential(credential);

  final FirebaseUser user = signInResult.user;


  return user;


I've tried it on an Android 9.0 (Pie) emulator and it still doesn't work.

Related Questions

Logic Behind Social Login

Updated March 22, 2017 12:26 PM