flutter_facebook_plugin

Dart package: https://pub.dev/packages/flutter_facebook_plugin

Flutter Facebook to Login and Sharing dialogs

Add easily Facebook login to your application and after succesful login call the link Facebook sharing dialog.

Getting Started

To use this plugin, add flutter_facebook_plugin as a dependency in your pubspec.yaml file.

Setup android

  • You need to complete Step 1
  • Skip Step 2 and Step 3

Complete Step 4. Edit Your Resources and Manifest

  • Add values to /android/app/src/main/res/values/strings.xml (create file if it doesn't exist) Remember to put your correct Facebook App Id.
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="facebook_app_id">1234</string>
    <string name="fb_login_protocol_scheme">fb1234</string>
</resources>
  • Add a meta-data element and activities to android/app/src/main/AndroidManifest.xml, section application:
    <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>
  • Add a uses-permission element to the manifest after the application element:
<uses-permission android:name="android.permission.INTERNET"/>
  • Complete Step 5. Associate Your Package Name and Default Class with Your App. (Skip all the step 6 if you already created the account in Facebook developers).
  • Set Package Name - your package name for Android application (attribute package in AndroidManifest.xml).
  • Set Default Activity Class Name - your main activity class (with package). By default it would be LoginActivity.java.
  • Click "Save".
  • Complete Step 6. Provide the Development and Release Key Hashes for Your App.

  • Skip the next steps.

Setup iOS

  • Complete Step 1. Select an app or create a new app. If you already created an app during an Android setup process than use it.
  • Skip Step 2 "Set up Your Development Environment" and Step 3 "Integrate the Facebook SDK"
  • Add your Bundle Identifier - set Bundle Identifier (you can find it in Xcode: Runner - Target Runner - General, section Identity, field Bundle Identifier) and "Save". Maybe in the Flutter root you will need to assign manually in (ios/Runner.xcodeproj/project.pbxproj) search all the PRODUCT_BUNDLE_IDENTIFIER and put the new Bundle Identifier

Complete Step 4. Configure Your Project

  • Configure Info.plist (ios/Runner/Info.plist):
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fbAPP-ID</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>APP-ID</string>
<key>FacebookClientToken</key>
<string>CLIENT-TOKEN</string>
<key>FacebookDisplayName</key>
<string>APP-NAME</string>
  • Also add to Info.plist body:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>

Complete Step 5. Connect Your App Delegate

  • In Xcode Connect Your App Delegate (Runner/Runner/AppDelegate), with the next code
import Flutter
import FBSDKCoreKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    //Facebook support
      FBSDKCoreKit.ApplicationDelegate.shared.application(
              application,
              didFinishLaunchingWithOptions: launchOptions
          )
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
    override func application(
            _ application: UIApplication,
            open url: URL,
            sourceApplication: String?,
            annotation: Any
        ) -> Bool {

            return ApplicationDelegate.shared.application(
                application, open: url,
                sourceApplication: sourceApplication,
                annotation: annotation
            )
        }
      
    override func application(
    _ app: UIApplication,
    open url: URL,
    options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
ApplicationDelegate.shared.application(
    app,
    open: url,
    sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
    annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
    }
        }