🧔 Google Sign In
Authenticate with Google using FlutterFire
Auth Service
Implement Google Login in the auth service.
services/auth.dart
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
class AuthService {
// ...
Future<void> googleLogin() async {
try {
final googleUser = await GoogleSignIn().signIn();
if (googleUser == null) return;
final googleAuth = await googleUser.authentication;
final authCredential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
await FirebaseAuth.instance.signInWithCredential(authCredential);
} on FirebaseAuthException catch (e) {
// handle error
}
}
}
Login Screen
Add Google Sign In to the login screen column.
login.dart
LoginButton(
text: 'Sign in with Google',
icon: FontAwesomeIcons.google,
color: Colors.blue,
loginMethod: AuthService().googleLogin,
),