flutter_facebook_login 3.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

flutter_facebook_login #

pub package Build Status Coverage Status

A Flutter plugin for using the native Facebook Login SDKs on Android and iOS.

AndroidX support #

Installation #

To get things up and running, you'll have to declare a pubspec dependency in your Flutter project. Also some minimal Android & iOS specific configuration must be done, otherise your app will crash.

On your Flutter project #

See the installation instructions on pub.

Android #

This assumes that you've done the "Associate Your Package Name and Default Class with Your App" and "Provide the Development and Release Key Hashes for Your App" in the the Facebook Login documentation for Android site.

After you've done that, find out what your Facebook App ID is. You can find your Facebook App ID in your Facebook App's dashboard in the Facebook developer console.

Once you have the Facebook App ID figured out, youll have to do two things.

First, copy-paste the following to your strings resource file. If you don't have one, just create it.

<your project root>/android/app/src/main/res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">Your App Name here.</string>

    <!-- Replace "000000000000" with your Facebook App ID here. -->
    <string name="facebook_app_id">000000000000</string>

      Replace "000000000000" with your Facebook App ID here.
      **NOTE**: The scheme needs to start with `fb` and then your ID.
    <string name="fb_login_protocol_scheme">fb000000000000</string>

Then you'll just have to copy-paste the following to your Android Manifest:

<your project root>/android/app/src/main/AndroidManifest.xml

<meta-data android:name="com.facebook.sdk.ApplicationId"

<activity android:name="com.facebook.FacebookActivity"
    android:label="@string/app_name" />

        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="@string/fb_login_protocol_scheme" />

A sample of a complete AndroidManifest file can be found here.


iOS #

This assumes that you've done the "Register and Configure Your App with Facebook" step in the the Facebook Login documentation for iOS site. (Note: you can skip "Step 2: Set up Your Development Environment" and "Step 5: Connect Your App Delegate").

After you've done that, find out what your Facebook App ID is. You can find your Facebook App ID in your Facebook App's dashboard in the Facebook developer console.

Once you have the Facebook App ID figured out, then you'll just have to copy-paste the following to your Info.plist file, before the ending </dict></plist> tags. (NOTE: If you are using this plugin in conjunction with for example google_sign_in plugin, which also requires you to add CFBundleURLTypes key into Info.plist file, you need to merge them together).

<your project root>/ios/Runner/Info.plist

    ... Some other CFBundleURLTypes definition.
              Replace "000000000000" with your Facebook App ID here.
              **NOTE**: The scheme needs to start with `fb` and then your ID.


<!-- Replace "000000000000" with your Facebook App ID here. -->

<!-- Replace "YOUR_APP_NAME" with your Facebook App name. -->


A sample of a complete Info.plist file can be found here.


How do I use it? #

The library tries to closely match the native Android & iOS login SDK APIs where possible. For complete API documentation, just see the source code. Everything is documented there.

Since sample code is worth more than one page of documentation, here are the usual cases covered:

import 'package:flutter_facebook_login/flutter_facebook_login.dart';

final facebookLogin = FacebookLogin();
final result = await facebookLogin.logInWithReadPermissions(['email']);

switch (result.status) {
  case FacebookLoginStatus.loggedIn:
  case FacebookLoginStatus.cancelledByUser:
  case FacebookLoginStatus.error:

You can also change the visual appearance of the login dialog. For example:

// Let's force the users to login using the login dialog based on WebViews. Yay!
facebookLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;

The complete API documentation lives with the source code, which can be found here.

Getting the Facebook profile of a signed in user #

For now, this feature isn't going to be integrated into this plugin. See the discussion here.

However, you can get do this in four lines of Dart code:

final result = await facebookSignIn.logInWithReadPermissions(['email']);
final token = result.accessToken.token;
final graphResponse = await http.get(
final profile = JSON.decode(graphResponse.body);

The profile variable will now contain the following information:

   "name": "Iiro Krankka",
   "first_name": "Iiro",
   "last_name": "Krankka",
   "email": "iiro.krankka\u0040gmail.com",
   "id": "<user id here>"

Troubleshooting #

If you haven't completed AndroidX setup in your Flutter project, your project might not build. The simple solution is adding 2 lines in your android/gradle.properties:


For more, see "AndroidX compatibility" in the official Flutter documentation.

3.0.0 #

  • Update Android & iOS Facebook Login dependencies to 5.5
  • Removed deprecated method loginWithPublishPermissions and renamed loginWithReadPermission to login
  • The behavior parameter is now ignored on iOS as it is not supported anymore by the Facebook Login SDK
  • #122: Fix expiration date crashes in 32-bit iOS devices.
  • Bump iOS deployment target to 9.0

2.0.1 #

  • #128: Pin down FBSDKCoreKit to the same version as FBSDKLoginKit.

2.0.0 #

  • Breaking change: migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

1.2.0 #

  • Update Android & iOS Facebook Login dependencies
  • Fix failing equals() in FacebookAccessToken
  • Fix "could not find class 'android.view.autofill.AutofillManager'" error on Android
  • Fix the "{com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Unknown error building URL.}" error on iOS
  • Add FacebookAccessToken#isValid() for checking if the access token is expired or not

Breaking change:

The FacebookLogin#isLoggedIn now checks if the currentAccessToken is expired or not, while it previously only checked if currentAccessToken was non-null.

1.1.1 #

  • Fix occasional hangs/freezes by introducing a slight artifical delay after getting the result from Facebook login.

1.1.0 #

  • Dart 2 support! There should not be any breaking changes. Please do file issues if you have problems.

1.0.3 #

  • Fixed potential crash and documented iOS logout issues when using the webOnly login behavior.

1.0.2 #

  • Added new isLoggedIn and currentAccessToken getters which make it easier to log the user in automatically.

1.0.1 #

  • Fixed the podspec definition for the iOS project.

1.0.0 #

  • Initial release.


import 'dart:async';

import 'package:flutter_facebook_login/flutter_facebook_login.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {
  static final FacebookLogin facebookSignIn = new FacebookLogin();

  String _message = 'Log in/out by pressing the buttons below.';

  Future<Null> _login() async {
    final FacebookLoginResult result =
        await facebookSignIn.logIn(['email']);

    switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        final FacebookAccessToken accessToken = result.accessToken;
         Logged in!
         Token: ${accessToken.token}
         User id: ${accessToken.userId}
         Expires: ${accessToken.expires}
         Permissions: ${accessToken.permissions}
         Declined permissions: ${accessToken.declinedPermissions}
      case FacebookLoginStatus.cancelledByUser:
        _showMessage('Login cancelled by the user.');
      case FacebookLoginStatus.error:
        _showMessage('Something went wrong with the login process.\n'
            'Here\'s the error Facebook gave us: ${result.errorMessage}');

  Future<Null> _logOut() async {
    await facebookSignIn.logOut();
    _showMessage('Logged out.');

  void _showMessage(String message) {
    setState(() {
      _message = message;

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Text(_message),
              new RaisedButton(
                onPressed: _login,
                child: new Text('Log in'),
              new RaisedButton(
                onPressed: _logOut,
                child: new Text('Logout'),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_facebook_login: ^3.0.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_facebook_login/flutter_facebook_login.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on May 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health suggestions

Format lib/flutter_facebook_login.dart.

Run flutter format to format lib/flutter_facebook_login.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
collection ^1.0.0 1.14.12
flutter 0.0.0
Transitive dependencies
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies