flutterflutter-dependencies

Flutter Google play services


I am creating a flutter game which utilise the Google play games. I use the game_services package.

When I tried to signIn, the logs says like this:

code:

void signin() async {
    try {
      print('account before: $account');
      account = await GamesServices.signIn();
      print('account: $account');
    } catch (e) {
      print('Error on signing: $e');
    }
}

@override
  void initState() {
    signin();
    super.initState();
  }

Logs: I/PlayService( 2169): isAuthenticated: true toString: com.google.android.gms.games.AuthenticationResult@c64b8d0 I/signin ( 2169): success I/flutter ( 2169): account: null

You can see even after saying success, the account String is empty.

I had completed these steps

  1. added game_services package
  2. included app_id in AndroidManifest
  3. created OAuth 2.0 Client ID and auth consent screen inside Google cloud project
  4. added xml file inside android/app/src/main/res/values/games-ids.xml

I want to know why account is null.


Solution

  • I solved it by changing the code like this:

    try {
          await GamesServices.signIn();
          if (await GamesServices.isSignedIn) {
            // user is signed
          }
    }
    

    Also make sure you added the SHA1 fingerprint of both debug and production inside the Credentials (OAuth Clients).