lecle_social_share 0.0.2 copy "lecle_social_share: ^0.0.2" to clipboard
lecle_social_share: ^0.0.2 copied to clipboard

outdated

A Flutter project support share files to social media (Facebook, Instagram,...). If you only want to share files on certain platforms, this plugin is made for you.

lecle_social_share #

A Flutter project support share file to social media (Facebook, Instagram,...). If you only want to share files on certain platforms, this plugin is made for you.

Current supported platform:

  • Facebook
  • Instagram

Android #

Paste the following attribute in the manifest tag in the AndroidManifest.xml


xmlns:tools="http://schemas.android.com/tools

For example:


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="your package...">

Add these permissions and queries to your AndroidManifest.xml


<queries>
    <!-- Explicit apps you know in advance about: -->
    <package android:name="com.instagram.android" />
    <package android:name="com.facebook.katana" />
</queries>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />  

Create xml folder and add a provider path file to it (for example: provider_paths_app.xml) in android/app/main/res and add the lines below to the created xml file

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="external_files"
        path="." />
</paths>

After created your own file provider and define your own path paste them into this and add to your AndroidManifest.xml


<provider android:name="androidx.core.content.FileProvider" 
        android:authorities="${applicationId}.[your_custom_fileProvider_path]"
    android:exported="false" android:grantUriPermissions="true">
    <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/[your_custom_fileProvider_file_name]" />
</provider>

Facebook app register #

  • In /android/app/src/main/values folder create a strings.xml file and add your facebook app id and facebook client token.
  • To get the facebook client token: Open your app on Meta for developer (link) > Settings > Advanced > Security > Application code
  • To get the facebook app id follow the Meta link above and go to your app Settings > Basic information > App ID
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="facebook_app_id">[facebook_app_id]</string>
    <string name="facebook_client_token">[facebook_client_token]</string>
</resources>
  • After complete the step above add these xml tags to your AndroidManifest.xml
  • To create the custom facebook theme: In android/app/src/main/res/values define your custom theme and add to the [your_custom_theme] in the activity below
  • Custom theme example:

<style name="com_facebook_activity_theme" parent="@style/Theme.AppCompat.NoActionBar">
  <item name="android:windowIsTranslucent">true</item>
  <item name="android:windowBackground">@android:color/transparent</item>
  <item name="android:windowNoTitle">true</item>
</style>


<provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProvider[your_facebook_app_id]"
    android:exported="true" />

<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:theme="@style/[your_custom_theme]" />

<activity android:name="com.facebook.CustomTabMainActivity" />
<activity android:name="com.facebook.CustomTabActivity" android:exported="true" tools:node="merge">
<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="fbconnect" android:host="cct.${applicationId}" />
</intent-filter>
</activity>

iOS #

Open Xcode and change your deployment target to iOS 11

Add these lines to your Info.plist file


<key>CFBundleURLTypes</key>
<array>
<dict>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>fb[your_facebook_app_id]</string>
    </array>
</dict>
</array>

<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
<string>fb</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fbapi</string>
<string>facebook-reels</string>
<string>facebook-stories</string>
</array>

<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) needs permission to access photos and videos on your device</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) does not require access to the microphone.</string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) requires access to the camera.</string>

<key>FacebookAppID</key>
<string>[your_facebook_app_id]</string>
<key>FacebookClientToken</key>
<string>[your_facebook_client_token]</string>
<key>FacebookDisplayName</key>
<string>[your_facebook_app_display_name]</string>

<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>

The facebook app id and facebook client token you can get by complete the steps mentioned on Android config

Add these lines to the AppDelegate.swift file

import FBSDKCoreKit

// Put these lines in the application function
FBSDKCoreKit.ApplicationDelegate.shared.application(
        application,
        didFinishLaunchingWithOptions: launchOptions
)

Facebook features #

Working on both platform #


static Future<dynamic> shareVideoToFacebook();
static Future<dynamic> sharePhotoToFacebook();
static Future<dynamic> shareFeedContentToFacebook();
static Future<dynamic> shareLinkContentToFacebook();
static Future<dynamic> shareVideoMediaContentToFacebook();
static Future<dynamic> sharePhotoMediaContentToFacebook();
static Future<dynamic> shareVideoAndPhotoMediaContentToFacebook();

Features for Android platform #


static Future<dynamic> shareImageBackgroundAssetToFacebookStoryWithIntent();
static Future<dynamic> shareVideoBackgroundAssetToFacebookStoryWithIntent();
static Future<dynamic> shareStickerAssetToFacebookStoryWithIntent();
static Future<dynamic> shareBitmapImageBackgroundAssetToFacebookStory();
static Future<dynamic> shareImageBackgroundAssetToFacebookStory();
static Future<dynamic> shareVideoBackgroundAssetToFacebookStory();
static Future<dynamic> shareVideoToFacebookReelsWithIntent();

Features for iOS platform #


static Future<dynamic> shareImageBackgroundAssetToFacebookStoryiOS();
static Future<dynamic> shareVideoBackgroundAssetToFacebookStoryiOS();
static Future<dynamic> shareStickerAssetToFacebookStoryiOS();
static Future<dynamic> shareBackgroundImageAndStickerToFacebookStoryiOS();
static Future<dynamic> shareBackgroundVideoToReelsiOS();

Instagram features #


static Future<dynamic> shareVideoToInstagram();
static Future<dynamic> sharePhotoToInstagram();

Example #

Facebook #

  • static Future<dynamic> shareVideoToFacebook()

ElevatedButton(
  onPressed: () async {
    var video = await _pickFile(FileType.video);
    if (video != null) {
      LecleSocialShare.shareVideoToFacebook(
        filePath: video.paths[0],
        dstPath: 'save_folder_path',
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    }
  },
  child: const Text('Share video to facebook'),
),

  • static Future<dynamic> sharePhotoToFacebook()

ElevatedButton(
  onPressed: () async {
    var image = await _picker.pickImage(source: ImageSource.gallery);
    if (image != null) {
      LecleSocialShare.sharePhotoToFacebook(
        filePath: image.path,
        dstPath: 'save_folder_path',
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    }
  },
  child: const Text('Share photo to facebook'),
),

  • static Future<dynamic> shareFeedContentToFacebook()

ElevatedButton(
  onPressed: () {
    LecleSocialShare.shareFeedContentToFacebook(
      link: "https://pub.dev",
      linkName: "pub",
      hashtag: "flutter_pub",
    );
  },
  child: const Text('Share feed content to facebook'),
),

  • static Future<dynamic> shareLinkContentToFacebook()

ElevatedButton(
  onPressed: () {
    LecleSocialShare.shareLinkContentToFacebook(
      contentUrl: "https://pub.dev",
    );
  },
  child: const Text('Share link content to facebook'),
),

  • static Future<dynamic> shareVideoMediaContentToFacebook()

ElevatedButton(
  onPressed: () async {
    var videos = await _pickFile(FileType.video, allowMultiple: true);

    LecleSocialShare.shareVideoMediaContentToFacebook(
      videoUrls: videos?.paths,
      fileProviderPath: 'your_custom_fileProvider_path',
    );
  },
  child: const Text('Share video media content to facebook'),
),

  • static Future<dynamic> sharePhotoMediaContentToFacebook()

ElevatedButton(
  onPressed: () async {
    var images = await _picker.pickMultiImage();

    LecleSocialShare.sharePhotoMediaContentToFacebook(
      imageUrls: images?.map((image) => image.path).toList(),
      fileProviderPath: 'your_custom_fileProvider_path',
    );
  },
  child: const Text('Share photo media content to facebook'),
),

  • static Future<dynamic> shareVideoAndPhotoMediaContentToFacebook()

// Not working on iOS platform for now
ElevatedButton(
  onPressed: () async {
    imageUrls = (await _picker.pickMultiImage())?.map((image) => image.path).toList();
    videoUrls = (await _pickFile(FileType.video, allowMultiple: true))?.paths;

    LecleSocialShare.shareVideoAndPhotoMediaContentToFacebook(
      imageUrls: imageUrls,
      videoUrls: videoUrls,
      fileProviderPath: 'your_custom_fileProvider_path',
    );
  },
  child: const Text('Share video and photo media content to facebook'),
),

  • static Future<dynamic> shareImageBackgroundAssetToFacebookStoryWithIntent()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var image = await _picker.pickImage(source: ImageSource.gallery);

      LecleSocialShare.shareImageBackgroundAssetToFacebookStoryWithIntent(
        appId: 'your_facebook_app_id',
        imagePath: image?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share image background asset to facebook story with intent'),
  ),
),

  • static Future<dynamic> shareVideoBackgroundAssetToFacebookStoryWithIntent()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var video = await _picker.pickVideo(source: ImageSource.gallery);
      LecleSocialShare.shareVideoBackgroundAssetToFacebookStoryWithIntent(
        appId: 'your_facebook_app_id',
        videoPath: video?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share video background asset to facebook story with intent'),
  ),
),

  • static Future<dynamic> shareStickerAssetToFacebookStoryWithIntent()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var image = await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.shareStickerAssetToFacebookStoryWithIntent(
        appId: 'your_facebook_app_id',
        stickerPath: image?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share sticker background asset to facebook story with intent'),
  ),
),

  • static Future<dynamic> shareBitmapImageBackgroundAssetToFacebookStory()

// ShareStoryContent of Facebook SDK is not working for now you can use 
// the share methods using intent instead.
Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var image = await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.shareBitmapImageBackgroundAssetToFacebookStory(
        imagePath: image?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share bitmap image background asset to facebook story'),
  ),
),

  • static Future<dynamic> shareImageBackgroundAssetToFacebookStory()

// ShareStoryContent of Facebook SDK is not working for now you can use 
// the share methods using intent instead.
Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var image = await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.shareImageBackgroundAssetToFacebookStory(
        photoBackgroundAssetPath: image?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share photo background asset to facebook story'),
  ),
),

  • static Future<dynamic> shareVideoBackgroundAssetToFacebookStory()

// ShareStoryContent of Facebook SDK is not working for now you can use 
// the share methods using intent instead.
Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var video = await _picker.pickVideo(source: ImageSource.gallery);
      LecleSocialShare.shareVideoBackgroundAssetToFacebookStory(
        videoBackgroundAssetPath: video?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share video background asset to facebook story'),
  ),
),

  • static Future<dynamic> shareVideoToFacebookReelsWithIntent()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var video = await _picker.pickVideo(source: ImageSource.gallery);
      var sticker = await _picker.pickImage(source: ImageSource.gallery);

      LecleSocialShare.shareVideoToFacebookReelsWithIntent(
        filePath: video?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
        appId: 'your_facebook_app_id',
        stickerPath: sticker?.path,
      );
    },
    child: const Text('Share video asset with sticker (optional) to facebook reels'),
  ),
),

  • static Future<dynamic> shareImageBackgroundAssetToFacebookStoryiOS()

Visibility(
  visible: Platform.isIOS,
  child: ElevatedButton(
    onPressed: () async {
      var image = await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.shareImageBackgroundAssetToFacebookStoryiOS(
        photoBackgroundAssetPath: image?.path,
        appId: 'your_facebook_app_id',
      );
    },
    child: const Text('Share image background asset to facebook story iOS'),
  ),
),

  • static Future<dynamic> shareVideoBackgroundAssetToFacebookStoryiOS()

Visibility(
  visible: Platform.isIOS,
  child: ElevatedButton(
    onPressed: () async {
      var video = await _picker.pickVideo(source: ImageSource.gallery);
      LecleSocialShare.shareVideoBackgroundAssetToFacebookStoryiOS(
        videoBackgroundAssetPath: video?.path,
        appId: 'your_facebook_app_id',
      );
    },
    child: const Text('Share video background asset to facebook story iOS'),
  ),
),

  • static Future<dynamic> shareStickerAssetToFacebookStoryiOS()

Visibility(
  visible: Platform.isIOS,
  child: ElevatedButton(
    onPressed: () async {
      var sticker = await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.shareStickerAssetToFacebookStoryiOS(
        stickerAssetPath: sticker?.path,
        appId: 'your_facebook_app_id',
      );
    },
    child: const Text('Share sticker asset to facebook story iOS'),
  ),
),

  • static Future<dynamic> shareBackgroundImageAndStickerToFacebookStoryiOS()

Visibility(
  visible: Platform.isIOS,
  child: ElevatedButton(
    onPressed: () async {
      var images = await _picker.pickMultiImage();
      var stickers = await _picker.pickMultiImage();

      LecleSocialShare.shareBackgroundImageAndStickerToFacebookStoryiOS(
        photoBackgroundAssetPaths: images?.map((image) => image.path).toList(),
        stickerAssetPaths: stickers?.map((image) => image.path).toList(),
        appId: 'your_facebook_app_id',
      );
    },
    child: const Text('Share background image and sticker asset to facebook story iOS'),
  ),
),

  • static Future<dynamic> shareBackgroundVideoToReelsiOS()

Visibility(
  visible: Platform.isIOS,
  child: ElevatedButton(
    onPressed: () async {
      var video = await _picker.pickVideo(source: ImageSource.gallery);

      LecleSocialShare.shareBackgroundVideoToReelsiOS(
        appId: 'your_facebook_app_id',
        backgroundVideoPath: video?.path,
      );
    },
    child: const Text('Share video asset to facebook reels iOS'),
  ),
),

Instagram #

  • static Future<dynamic> shareVideoToInstagram()

ElevatedButton(
  onPressed: () async {
    var video = await _picker.pickVideo(source: ImageSource.gallery);

    if (video != null) {
      _shareVideoToInstagram(
        filePath: video.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    }
  },
  child: const Text('Share video to instagram'),
),

  • static Future<dynamic> sharePhotoToInstagram()

ElevatedButton(
  onPressed: () async {
    var image = await _picker.pickImage(source: ImageSource.gallery);

    if (image != null) {
      LecleSocialShare.sharePhotoToInstagram(
        filePath: image.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    }
  },
  child: const Text('Share photo to instagram'),
),

26
likes
0
pub points
82%
popularity

Publisher

verified publisherlecle.vn

A Flutter project support share files to social media (Facebook, Instagram,...). If you only want to share files on certain platforms, this plugin is made for you.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on lecle_social_share