Facebook Login in Flutter With Firebase Auth

Facebook Login in Flutter With Firebase Auth

You can integrate your social login within 7 easy steps...

ยท

1 min read

Table of contents

No heading

No headings in the article.

Step 0: Create a Firebase Project and put facebook credentials on their

image_2022-06-13_194502719.png

Step 1: packages

Step 2: goto: android/app/build.gradle

and add these dependencies

image_2022-06-13_194625137.png

apply plugin: 'com.google.gms.google-services'

and this also

image.png

implementation platform('com.google.firebase:firebase-bom:30.0.1')

Step 3: goto android/app/src/main/res/values/

and create a file save as > strings.xml

image_2022-06-13_195032351.png

Step 4: Add into AndroidMainefest.xml

image.png

Step 5: Add a dependency at the project level android/build.gradle

classpath 'com.google.gms:google-services:4.3.10'

image_2022-06-13_195910667.png

Step 6: Initialize Firebase

Don't forget to initialize firebase

like this:

void main()async{

  await Firebase.initializeApp();
runApp(YourApp());

}

Step 7: Use this Snippet to Create your Login Function

final res=await FacebookAuth.instance.login();
  final userData=await FacebookAuth.instance.getUserData();
  switch(res.status){
    case LoginStatus.success:
      {
        final AuthCredential facebookCredential = FacebookAuthProvider.credential(res.accessToken.token.toString());
        var credential  = await FirebaseAuth.instance.signInWithCredential(facebookCredential);

       print(credential.accessToken.token);




      }


  }

That's it Congratulation ๐ŸŽŠ you have integrated a Facebook login into your application...

**Note: don't forget to add your google_services.json in android/app/ and add your sha1 in firebase console for testing..

**

For more like and follow...

ย