Google Sign In - in Flutter
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
class KidGoogleSignIn{
static final FirebaseAuth _auth=FirebaseAuth.instance;
static final GoogleSignIn _googleSignIn=GoogleSignIn();
// Sign in
static Future<dynamic> SignInGmail()async{
try{
final GoogleSignInAccount? _googleSignInAccount= await _googleSignIn.signIn();
final GoogleSignInAuthentication? _googleSignInAuthentication = await _googleSignInAccount!.authentication;
final AuthCredential credential= GoogleAuthProvider.credential(
accessToken: _googleSignInAuthentication!.accessToken,
idToken: _googleSignInAuthentication.idToken,
);
await _auth.signInWithCredential(credential);
}
catch(e){
print(e);
}
}
// Sign out
static Future kidSignOut()async{
try{
await _auth.signOut();
}catch(e){
print(e);
}
}
// User
static User getUser(){
User user=_auth.currentUser!;
return user;
}
}
No comments:
Post a Comment