Add Google Sign In to Flutter

Tiempo de lectura: 3 minutos

Today we are going to learn how we can implement Google authentication in our Flutter app.

Let’s go to Google Cloud Platform (https://cloud.google.com/) and click on Console

Now select our project (if we already have it created by Firebase) or create a new one.

Now search for: oauth clients

Choose External:

Fill in the application name and the requested data:

Then fill in the Developer contact information:

Click on save and continue.

In the next screen, do not touch anything and click again on save and continue.

Do the same for the optional information.

Now we have to add the allowed keys, for this we go to Credentials

Click on Create Credentials and Choose OAuth Client ID

Choose type iOS.

Add the package id which can be found in iOS/projectName/Info.plist

Add the SHA1 key with the command.

And it will return the key or keys we have configured.

We will have to add the debug key and also release (if you have it) (Here I indicate how you can create one https://devcodelight.com/generate-an-apk-aab-release-with-flutter-and-visual-stuido-code/), if you don’t have the release key, it doesn’t matter, you can first try with debug.

Copy the output that says SHA1:

Now the Flutter code is added:

  google_sign_in: ^6.2.1

 

print("OAuth Token: " + (auth.idToken ?? ""));

Remember to add the code in:

To display the login button:

LoginGoogle(),

Return only the Android code after the Flutter code is created, we have to modify the android folder.

For this we go to android/build.gradle and add:

Leaving it like this:

And now we go to android/app/build.gradle and add:

apply plugin: 'com.google.gms.google-services'

Leaving it like this:

Leave a Comment