Google Sign in Flutter Firebase for Android and IOS, or Google Login Flutter with the latest update 7.1.1. Implement Google Sign-In in your Flutter app using Firebase Authentication, step-by-step for both Android and iOS.
Create & Configure Firebase Project
Go to Firebase Console, click Add Project → give your project a name → continue with default settings. Add Firebase to Your Flutter App (Using FlutterFire CLI). The FlutterFire CLI makes setup super easy. Simply follow these two commands, and it will complete everything required for Firebase setup on both Android and iOS.
dart pub global activate flutterfire_cli flutterfire configure
For iOS, open the ios/Podfile
. Uncomment the platform
line and set the minimum iOS version to 15
For Android Setup, Open android/app/build.gradle.kts
. Set compileSdk 35 and ndkVersion 27.0.12077973.
Last, add the package and initialize a Firebase in main.dart
firebase_core: ^4.0.0 google_sign_in: ^7.1.1 firebase_auth: ^6.0.0
void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(MyApp()); }
At this point, with just these steps, Firebase is fully connected to both Android and iOS.
Next Steps
- Enable Google Sign-In in Firebase
- Add SHA Keys for Android
- Replace Config Files
After adding the keys, you must download and replace your Firebase config files: Download the new
google-services.json
(Android) and replace it.Download the new
GoogleService-Info.plist
(iOS) and replace it
Now that you have completed the Android app setup for Google Sign-In, you need to do one additional step for iOS.
- Add the client ID from the
GoogleService-Info.plist
into your app’s[your_project]/ios/Runner/Info.plist
file.
<key>GIDClientID</key> <!-- TODO Replace this value: --> <!-- Copied from GoogleService-Info.plist key CLIENT_ID --> <string>[YOUR IOS CLIENT ID]</string>
- Then add the
CFBundleURLTypes
attributes below into the[my_project]/ios/Runner/Info.plist
file<!-- Put me in the [my_project]/ios/Runner/Info.plist file --> <!-- Google Sign-in Section --> <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <!-- TODO Replace this value: --> <!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID --> <string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string> </array> </dict> </array> <!-- End of the Google Sign-in Section -->
✅ Finally, your app is fully connected to Firebase with Google Sign-In support for both Android and iOS.
GoogleSignInService
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:google_sign_in/google_sign_in.dart'; // Google Sign-In Service Class class GoogleSignInService { static final FirebaseAuth _auth = FirebaseAuth.instance; static final GoogleSignIn _googleSignIn = GoogleSignIn.instance; static bool isInitialize = false; static Future<void> initSignIn() async { if (!isInitialize) { await _googleSignIn.initialize( serverClientId: '484988555302-d91nev5jn5sit0qoe3oehpgpp58pl5mt.apps.googleusercontent.com', ); } isInitialize = true; } // Sign in with Google static Future<UserCredential?> signInWithGoogle() async { try { initSignIn(); final GoogleSignInAccount googleUser = await _googleSignIn.authenticate(); final idToken = googleUser.authentication.idToken; final authorizationClient = googleUser.authorizationClient; GoogleSignInClientAuthorization? authorization = await authorizationClient .authorizationForScopes(['email', 'profile']); final accessToken = authorization?.accessToken; if (accessToken == null) { final authorization2 = await authorizationClient.authorizationForScopes( ['email', 'profile'], ); if (authorization2?.accessToken == null) { throw FirebaseAuthException(code: "error", message: "error"); } authorization = authorization2; } final credential = GoogleAuthProvider.credential( accessToken: accessToken, idToken: idToken, ); final UserCredential userCredential = await FirebaseAuth.instance .signInWithCredential(credential); final User? user = userCredential.user; if (user != null) { final userDoc = FirebaseFirestore.instance .collection('users') .doc(user.uid); final docSnapshot = await userDoc.get(); if (!docSnapshot.exists) { await userDoc.set({ 'uid': user.uid, 'name': user.displayName ?? '', 'email': user.email ?? '', 'photoURL': user.photoURL ?? '', 'provider': 'google', 'createdAt': FieldValue.serverTimestamp(), }); } } return userCredential; } catch (e) { print('Error: $e'); rethrow; } } // Sign out static Future<void> signOut() async { try { await _googleSignIn.signOut(); await _auth.signOut(); } catch (e) { print('Error signing out: $e'); throw e; } } // Get current user static User? getCurrentUser() { return _auth.currentUser; } }