lecle_social_share 0.1.2+1 copy "lecle_social_share: ^0.1.2+1" to clipboard
lecle_social_share: ^0.1.2+1 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, etc.). If you only want to share files on certain platforms, this plugin is made for you.

Current supported platform:

  • Facebook
  • Instagram
  • Messenger

There are static instances in LecleSocialShare class represent for:

  • F: Facebook
  • I: Instagram
  • M: Messenger

Simply use LecleSocialShare class and call the instance of which platform you want to share then call the corresponding method from the instance

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" />
    <package android:name="com.facebook.orca" />
</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>
<string>fb-messenger-share-api</string>
<string>fb-messenger</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 #


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

Features for Android platform #


Future<dynamic> shareImageBackgroundAssetToFacebookStoryAndroid();
Future<dynamic> shareVideoBackgroundAssetToFacebookStoryAndroid();
Future<dynamic> shareStickerAssetToFacebookStoryAndroid();
Future<dynamic> shareBitmapImageBackgroundAssetToFacebookStory();
Future<dynamic> shareImageBackgroundAssetToFacebookStory();
Future<dynamic> shareVideoBackgroundAssetToFacebookStory();
Future<dynamic> shareVideoToFacebookReelsAndroid();

Features for iOS platform #


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

Instagram features #


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

Messsenger features #

Features for Android platform #


Future<dynamic> shareVideoToMessengerAndroid();
Future<dynamic> sharePhotoToMessengerAndroid();
Future<dynamic> sendMessageToMessengerAndroid();

Features for iOS platform #


Future<dynamic> shareVideoToMessengeriOS();
Future<dynamic> sharePhotoToMessengeriOS();
Future<dynamic> shareLinkContentToMessengeriOS();

Example #

Facebook #

  • Future<dynamic> shareVideoToFacebook()

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

  • Future<dynamic> sharePhotoToFacebook()

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

  • Future<dynamic> shareFeedContentToFacebook()

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

  • Future<dynamic> shareLinkContentToFacebook()

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

  • Future<dynamic> shareVideoMediaContentToFacebook()

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

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

  • Future<dynamic> sharePhotoMediaContentToFacebook()

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

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

  • 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.F.shareVideoAndPhotoMediaContentToFacebook(
      imageUrls: imageUrls,
      videoUrls: videoUrls,
      fileProviderPath: 'your_custom_fileProvider_path',
    );
  },
  child: const Text('Share video and photo media content to facebook'),
),

  • Future<dynamic> shareImageBackgroundAssetToFacebookStoryAndroid()

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

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

  • Future<dynamic> shareVideoBackgroundAssetToFacebookStoryAndroid()

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

  • Future<dynamic> shareStickerAssetToFacebookStoryAndroid()

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

  • Future<dynamic> shareBitmapImageBackgroundAssetToFacebookStory()

// ShareStoryContent class in Facebook SDK is not working for now, you can use 
// Future<dynamic> shareImageBackgroundAssetToFacebookStoryAndroid() or Future<dynamic> shareStickerAssetToFacebookStoryAndroid()
// methods instead.
Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var image = await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.F.shareBitmapImageBackgroundAssetToFacebookStory(
        imagePath: image?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share bitmap image background asset to facebook story'),
  ),
),

  • Future<dynamic> shareImageBackgroundAssetToFacebookStory()

// ShareStoryContent class in Facebook SDK is not working for now, you can use 
// Future<dynamic> shareImageBackgroundAssetToFacebookStoryAndroid() or Future<dynamic> shareStickerAssetToFacebookStoryAndroid()
// methods instead.
Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var image = await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.F.shareImageBackgroundAssetToFacebookStory(
        photoBackgroundAssetPath: image?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share photo background asset to facebook story'),
  ),
),

  • Future<dynamic> shareVideoBackgroundAssetToFacebookStory()

// ShareStoryContent class in Facebook SDK is not working for now, you can use 
// Future<dynamic> shareVideoBackgroundAssetToFacebookStoryAndroid() method instead.
Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var video = await _picker.pickVideo(source: ImageSource.gallery);
      LecleSocialShare.F.shareVideoBackgroundAssetToFacebookStory(
        videoBackgroundAssetPath: video?.path,
        fileProviderPath: 'your_custom_fileProvider_path',
      );
    },
    child: const Text('Share video background asset to facebook story'),
  ),
),

  • Future<dynamic> shareVideoToFacebookReelsAndroid()

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.F.shareVideoToFacebookReelsAndroid(
        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'),
  ),
),

  • Future<dynamic> shareImageBackgroundAssetToFacebookStoryiOS()

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

  • Future<dynamic> shareVideoBackgroundAssetToFacebookStoryiOS()

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

  • Future<dynamic> shareStickerAssetToFacebookStoryiOS()

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

  • Future<dynamic> shareBackgroundImageAndStickerToFacebookStoryiOS()

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

      LecleSocialShare.F.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'),
  ),
),

  • Future<dynamic> shareBackgroundVideoToReelsiOS()

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

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

Instagram #

  • Future<dynamic> shareVideoToInstagram()

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

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

  • Future<dynamic> sharePhotoToInstagram()

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

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

Messenger #

  • Future<dynamic> shareVideoToMessengerAndroid()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var video =
          await _picker.pickVideo(source: ImageSource.gallery);
      LecleSocialShare.M.shareVideoToMessengerAndroid(
        videoPath: video?.path,
        fileProviderPath: '.social.share.fileprovider',
      );
    },
    child: const Text(
        'Share video background asset to messenger Android'),
  ),
),
  • Future<dynamic> sharePhotoToMessengerAndroid()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
    onPressed: () async {
      var image =
          await _picker.pickImage(source: ImageSource.gallery);
      LecleSocialShare.M.sharePhotoToMessengerAndroid(
        imagePath: image?.path,
        fileProviderPath: '.social.share.fileprovider',
      );
    },
    child: const Text(
        'Share photo background asset to messenger Android'),
  ),
),
  • Future<dynamic> sendMessageToMessengerAndroid()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
  onPressed: () async {
    LecleSocialShare.M.sendMessageToMessengerAndroid(
      message: 'https://pub.dev',
    );
  },
  child: const Text('Share message to messenger Android'),
  ),
),
  • Future<dynamic> shareVideoToMessengeriOS()

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

      LecleSocialShare.M.shareVideoToMessengeriOS(
        filePath: video?.path,
      );
    },
    child: const Text('Share video to messenger iOS'),
  ),
),
  • Future<dynamic> sharePhotoToMessengeriOS()

Visibility(
  visible: Platform.isAndroid,
  child: ElevatedButton(
  onPressed: () async {
    LecleSocialShare.M.sharePhotoToMessengeriOS(
      message: 'https://pub.dev',
    );
  },
  child: const Text('Share message to messenger Android'),
  ),
),
  • Future<dynamic> shareLinkContentToMessengeriOS()

Visibility(
  visible: Platform.isIOS,
  child: ElevatedButton(
  onPressed: () async {
    LecleSocialShare.M.shareLinkContentToMessengeriOS(
      contentUrl: 'https://pub.dev',
    );
  },
  child: const Text('Send message to messenger iOS'),
  ),
),
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