FlutterCore Logo
MENU
  • Home
  • Components ►
    • Alert
    • Button
    • Calendar
    • Color
    • Dialog
    • i18n
    • Indicator
    • Picker
    • Popup
    • Rating
    • Reports
    • Slider
    • Swipe
    • Tabbar
    • Table
    • Timeline
    • Toast
    • Web
  • Input ►
    • Authentication
    • Autocomplete
    • Date/Time Picker
    • Editor
    • Forms
    • Keyboard
    • Note
    • Password
    • Pin
    • Search
    • Text
    • Validation
    • Verification
  • Media ►
    • Audio
    • Charts
    • Gallery
    • Images
    • Maps
    • Music
    • Shape
    • Video
  • Ui ►
    • Animation
    • Cards
    • Carousel
    • Chat
    • Design
    • Drawer
    • Flip
    • Grid
    • Intro Page
    • Layout
    • ListView
    • Login Page
    • Material Design
    • Menu
    • Navigation
    • Progress
    • Splash Screen
  • Tutorial ►
    • Example
  • Application ►
    • Calculator
    • Clock
    • Library
    • Plugin
  • Home
  • Components
    • Alert
    • Button
    • Calendar
    • Color
    • Dialog
    • i18n
    • Indicator
    • Picker
    • Popup
    • Rating
    • Reports
    • Slider
    • Swipe
    • Tabbar
    • Table
    • Timeline
    • Toast
    • Web
  • Input
    • Authentication
    • Autocomplete
    • Date/Time Picker
    • Editor
    • Forms
    • Keyboard
    • Note
    • Password
    • Pin
    • Search
    • Text
    • Validation
    • Verification
  • Media
    • Audio
    • Charts
    • Gallery
    • Images
    • Maps
    • Music
    • Shape
    • Video
  • Ui
    • Animation
    • Cards
    • Carousel
    • Chat
    • Design
    • Drawer
    • Flip
    • Grid
    • Intro Page
    • Layout
    • ListView
    • Login Page
    • Material Design
    • Menu
    • Navigation
    • Progress
    • Splash Screen
  • Tutorial
    • Example
  • Application
    • Calculator
    • Clock
    • Library
    • Plugin

Flutter Facebook Login

June 17, 2020 totosugito Authentication, Verification 0

Flutter Facebook Login

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

  • if you want to avoid AndroidX, use version 1.2.0.
  • for AndroidX Flutter projects, use versions 2.0.0 and up.

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, otherwise 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, you’ll 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"?>
<resources>
    <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>
</resources>

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"
    android:value="@string/facebook_app_id"/>

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

<activity
    android:name="com.facebook.CustomTabActivity"
    android:exported="true">
    <intent-filter>
        <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" />
    </intent-filter>
</activity>

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

Done!

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

<key>CFBundleURLTypes</key>
<array>
    <!--
    <dict>
    ... Some other CFBundleURLTypes definition.
    </dict>
    -->
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <!--
              Replace "000000000000" with your Facebook App ID here.
              **NOTE**: The scheme needs to start with `fb` and then your ID.
            -->
            <string>fb000000000000</string>
        </array>
    </dict>
</array>

<key>FacebookAppID</key>

<!-- Replace "000000000000" with your Facebook App ID here. -->
<string>000000000000</string>
<key>FacebookDisplayName</key>

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

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-share-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

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

Done!

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.logIn(['email']);

switch (result.status) {
  case FacebookLoginStatus.loggedIn:
    _sendTokenToServer(result.accessToken.token);
    _showLoggedInUI();
    break;
  case FacebookLoginStatus.cancelledByUser:
    _showCancelledMessage();
    break;
  case FacebookLoginStatus.error:
    _showErrorOnUI(result.errorMessage);
    break;
}

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.logIn(['email']);
final token = result.accessToken.token;
final graphResponse = await http.get(
            'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${token}');
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:

android.useAndroidX=true
android.enableJetifier=true

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

Source Code

Please Visit Flutter Facebook Login Source Code at GitHub

Related posts:

Flutter Login Screen With FirebaseFlutter Login Screen With Firebase Flutter Simple AuthFlutter Simple Auth Flutter Simple Login ExampleFlutter Simple Login Example Flutter Login Screen With FirebaseFlutter Login Screen With Firebase
  • flutter login
Flutter Simple AuthPrevious

Flutter Simple Auth

Flutter Login ExampleNext

Flutter Login Example

Android Mining Monitor Application

Pool Supported : Ethermine, Nanopool, 2Miners, Flexpool, Herominers, Hiveon

Go to Google Playstore

Recent Posts

  • Flutter File UtilsFlutter File Utils
  • Flutter PDFFlutter PDF
  • Produ Flutter Task Cross PlatformProdu Flutter Task Cross Platform
  • Flutter Animation DirectorFlutter Animation Director
  • Draggable Flutter ListDraggable Flutter List
  • Flutter Section Table ViewFlutter Section Table View
  • Image and Location Picker FlutterImage and Location Picker Flutter

Categories

  • Alert 2
  • Animation 39
  • Application 58
  • Audio 11
  • Authentication 7
  • Autocomplete 3
  • Button 15
  • Calculator 4
  • Calendar 12
  • Cards 16
  • Carousel 2
  • Charts 16
  • Chat 3
  • Clock 2
  • Color 5
  • Components 144
  • Date/Time Picker 15
  • Design 26
  • Dialog 13
  • Drag and Drop 4
  • Drawer 5
  • Dropdown 5
  • Editor 3
  • Example 24
  • Flip 3
  • Forms 6
  • Gallery 5
  • Grid 11
  • i18n 4
  • Images 31
  • Indicator 16
  • Input 30
  • Intro Page 5
  • Keyboard 3
  • Layout 16
  • Library 34
  • ListView 22
  • Loading 10
  • Login Page 6
  • Machine Learning 2
  • Maps 20
  • Markdown 1
  • Material Design 6
  • Media 78
  • Menu 25
  • Music 11
  • Navigation 19
  • Note 6
  • Page 8
  • Password 7
  • Payment 1
  • PDF 1
  • Perallax Scroll 1
  • Picker 22
  • Pin 5
  • Plugin 16
  • Popup 5
  • Progress 13
  • Rating 2
  • Reports 2
  • Search 8
  • Shape 2
  • Slider 13
  • Splash Screen 1
  • Swipe 7
  • Switch 2
  • Tabbar 8
  • Table 3
  • Tagging 2
  • Text 13
  • Textfield 4
  • Timeline 4
  • To Do 15
  • Toast 5
  • Tutorial 4
  • Ui 48
  • Validation 2
  • Verification 4
  • Video 16
  • Web 2

Copyright © 2025 | WordPress Theme by MH Themes