How To Implement Google Login in Flutter?

1. Set Up Your Project:

  • Ensure your Flutter environment is set up.
  • Create a new Flutter project or open an existing one.

2. Configure Firebase Project:

  • Go to the Firebase Console.
  • Create a new Firebase project or select an existing one.
  • Add your Android and iOS app to the Firebase project and download the google-services.json (for Android) or GoogleService-Info.plist (for iOS) file.
  • Place these files in the respective directories of your Flutter project:
    • google-services.json in android/app.
    • GoogleService-Info.plist in ios/Runner.

3. Add Dependencies:

Open pubspec.yaml and add the following dependencies:
yaml

4. Configure Android:

  • Modify android/build.gradle:

Modify android/app/build.gradle:

5. Configure iOS:

Open ios/Runner/Info.plist and add:

Replace YOUR_REVERSED_CLIENT_ID with the reversed client ID from GoogleService-Info.plist.

6. Initialize Firebase:

Open main.dart and initialize Firebase:

7. Implement Google Sign-In:

  • Create a new file sign_in_demo.dart and add the following code:

8.Run Your App:

  • Run your Flutter app on an emulator or physical device.
  • Test the Google Sign-In functionality.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *