Working with Google SignIn in Flutter
Working with Google Sign-In in Flutter
Google Sign-In is a secure and convenient way for users to sign into your app. In this article, we will walk through the steps required to work with Google Sign-In in Flutter.
Create a Firebase Project
First, you need to create a new Firebase project:
- Navigate to the Firebase console.
- Click on “Add project”.
- Enter a project name, accept the terms of service, and click on “Create project”.
Once the project is created, you can select the project from the dashboard. The next step is to configure the Google Sign-In feature.
Configure Google Sign-In in Firebase
To configure Google Sign-In in Firebase:
- Navigate to the Authentication tab in the side menu.
- Select the “Sign-in method” tab.
- Enable the “Google” sign-in provider.
- Enter the SHA-1 certificate fingerprint from your Android application. (If you don’t have an Android application yet, you can leave this field blank for now).
- Click on “Save” at the bottom of the page.
Integrate Google Sign-In in Flutter
Now that the Google Sign-In feature is configured in Firebase, we need to integrate it into our Flutter app. To do this:
- Navigate to the Firebase console.
- Select the project that you created earlier.
- From the side menu, select “Project Settings”.
- Select the “General” tab.
- Scroll down to the “Your apps” section and click on “Add app”.
- Select “Android” and enter your Android package name. (This is the same package name that you used when creating the Firebase project).
- Download the google-services.json file and copy it into the / android / app folder of your Flutter project.
- Add the following lines to the dependencies section of your android/app/build.gradle file:
implementation 'com.google.firebase:firebase-core:16.0.6' implementation 'com.google.firebase:firebase-auth:16.1.0'
- Add the following lines to the dependencies section of your ios/Podfile:
pod 'Firebase/Core' pod 'Firebase/Auth'
- Run “flutter packages get” in the terminal.
- Finally, add the GoogleSignIn plugin to your pubspec.yaml file:
google_sign_in: ^4.0.7
Testing the Google Sign-In Functionality
Now that the integration is complete, you can test the Google Sign-In functionality in your app. To do this:
- Import the google_sign_in package.
- Call the GoogleSignIn.signIn() method and pass in the desired scopes.
- Handle the returned Future accordingly.
For more information on how to use the GoogleSignIn package, please refer to the official documentation here.
And that’s it! You should now be able to work with Google Sign-In in Flutter.