social_share_kit_facebook 0.1.0
social_share_kit_facebook: ^0.1.0 copied to clipboard
Facebook SDK add-on for social_share_kit. Upgrades ShareTarget.facebook to the native Share Dialog on both platforms, with real success, cancel and error reporting.
social_share_kit_facebook #
Facebook SDK add-on for social_share_kit.
The core package bundles no vendor SDKs, which leaves ShareTarget.facebook intent-only on Android and unsupported on iOS — Facebook's iOS app publishes no sharing URL scheme, so a direct share genuinely needs the SDK. Add this package and Facebook works properly on both platforms, with real success, cancel and error reporting.
Everyone else keeps a zero-setup core package. You only pay for this if you want it.
Install #
dependencies:
social_share_kit: ^0.2.0
social_share_kit_facebook: ^0.1.0
void main() {
SocialShareKitFacebook.register(); // once, before the first share
runApp(const MyApp());
}
Call sites do not change:
// now routed through the native Share Dialog
final result = await SocialShareKit.shareTo(
ShareTarget.facebook,
ShareContent.files(['/path/photo.jpg']),
);
result.status == ShareStatus.cancelled; // the user backed out — now detectable
capabilities(), supportedTargets() and installedTargets() all start reporting through the SDK for that one target automatically.
What changes #
| core alone | with this add-on | |
|---|---|---|
| Facebook on Android | plain intent; Facebook strips the text | native Share Dialog |
| Facebook on iOS | unsupportedPlatform |
native Share Dialog |
| Photos | via intent | up to 6, as SharePhotoContent |
| Video | via intent | 1, as ShareVideoContent |
| Link | via intent | ShareLinkContent |
| Cancellation | not detectable | reported as ShareStatus.cancelled |
| Setup needed | none | app id + client token (below) |
ShareTarget.facebookStory is not claimed by this add-on. The story composer works through the documented pasteboard/intent handoff and needs no SDK, so core keeps it.
Required setup #
This is the cost the core package avoids. All of it comes from Facebook's own integration requirements, not from this package.
Get an app id and client token from developers.facebook.com: Settings → Basic for the app id, Settings → Advanced → Security → Client token for the token.
Android #
android/app/src/main/res/values/strings.xml:
<resources>
<string name="facebook_app_id">YOUR_APP_ID</string>
<string name="facebook_client_token">YOUR_CLIENT_TOKEN</string>
</resources>
Inside <application> in android/app/src/main/AndroidManifest.xml:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<meta-data android:name="com.facebook.sdk.ClientToken"
android:value="@string/facebook_client_token" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:exported="false" />
<provider android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProviderYOUR_APP_ID"
android:exported="true" />
The provider authority has your app id appended with no separator — ...FacebookContentProvider1234567890. It cannot be declared by this package because the authority embeds a value only you know. Photos reach the Facebook app through it.
The <queries> entries and the FileProvider for video are handled by this add-on's manifest.
iOS #
ios/Runner/Info.plist:
<key>FacebookAppID</key>
<string>YOUR_APP_ID</string>
<key>FacebookClientToken</key>
<string>YOUR_CLIENT_TOKEN</string>
<key>FacebookDisplayName</key>
<string>Your App Name</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array><string>fbYOUR_APP_ID</string></array>
</dict>
</array>
Add fbapi and fb-messenger-share-api to your existing LSApplicationQueriesSchemes array — the SDK probes them to find the Facebook app.
ios/Runner/AppDelegate.swift:
import FBSDKCoreKit
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
Behaviour worth knowing #
Text is never pre-filled. Facebook has stripped captions the user did not type since Platform Policy 2.3, and the SDK drops them. This package sends ShareContent.text as a hashtag when it is one (a single #word), and otherwise leaves it to you — capabilities().prefillsText is false, which is the honest answer. Use SocialShareKit.copyToClipboard if you want the user to be able to paste it.
Photos and video cannot be mixed in one share; the dialog has no content type for it. Sending both returns unsupportedContent rather than silently dropping one.
Photos are downsampled to a 2048px longest edge before handing them over. Full-resolution decodes of modern camera images are a common out-of-memory crash, and Facebook re-encodes on upload anyway.
success means the dialog reported completion, which for Facebook is genuinely stronger than the core package's "the composer opened" — SharingDelegate and FacebookCallback fire on the real outcome.
Removing it #
Drop the dependency and the register() call. Facebook reverts to intent sharing on Android and unsupportedPlatform on iOS; nothing else in your code changes. SocialShareKitFacebook.unregister() does the same at runtime.
Licence #
MIT. See LICENSE.