signInWithFacebook method

Future<User?> signInWithFacebook(
  1. BuildContext context, {
  2. Color? progressBarColors,
  3. bool? isDisplayProgressBar,
})

Implementation

Future<User?> signInWithFacebook(BuildContext context,
    {Color? progressBarColors, bool? isDisplayProgressBar}) async {
  ProgressDialog.show(context,progressBarColors??Colors.black,isDisplayProgressBar??false);
  // Trigger the sign-in flow
  FacebookAuth.instance.logOut();
  FirebaseAuth.instance.signOut();
  try {
    final LoginResult loginResult = await FacebookAuth.instance.login(
        permissions: ["email", "public_profile"],
        loginBehavior: LoginBehavior.webOnly);
    print(loginResult.message);
    // Create a credential from the access token
    if (loginResult != null) {
      final OAuthCredential facebookAuthCredential =
      FacebookAuthProvider.credential(loginResult.accessToken!.token);
      ProgressDialog.hide();
      print(facebookAuthCredential);

      UserCredential result = await FirebaseAuth.instance
          .signInWithCredential(facebookAuthCredential);
      print("user="+result.user.toString());
      return result.user;
    }
  } on FirebaseAuthException catch (e) {
    ProgressDialog.hide();
    showToastMessage(e.message.toString());
    return null;
  } catch (e) {
    ProgressDialog.hide();
    print(e.toString());
    return null;
  }

  return null;
}