To use this we need to setup our flutter project, we need to add firebase_auth package and for sign in with google we need to add google_sign_in package in pubspace.yaml file.
google_sign_in: "^3.0.4"
firebase_auth: "^0.5.12"
Now you need to create project in firebase console https://console.firebase.google.com/ follow this link to create project, and enable sign in method in Authentication tab
/// Add the google services classpath
classpath 'com.google.gms:google-services:4.0.0'
/// Add this at bottom of file
apply plugin: 'com.google.gms.google-services'
/// sign in with google
Future<FirebaseUser> signInWithGoogle() async {
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = new GoogleSignIn();
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
FirebaseUser user = await firebaseAuth.signInWithGoogle(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
return user;
}
//To create new User
Future<FirebaseUser> createUser(PersonData userData) async {
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
return firebaseAuth.createUserWithEmailAndPassword(
email: userData.email, password: userData.password);
}
//To verify new User
Future<FirebaseUser> verifyUser(PersonData userData) {
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
return firebaseAuth.signInWithEmailAndPassword(
email: userData.email, password: userData.password);
}
For help getting started with Flutter, view our online documentation.