lecle_social_share 0.0.1 lecle_social_share: ^0.0.1 copied to clipboard
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.
import 'dart:async';
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:lecle_social_share/lecle_social_share.dart';
void main() {
runApp(
const MaterialApp(
home: MyApp(),
debugShowCheckedModeBanner: false,
),
);
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<String?>? videoUrls = [];
List<String?>? imageUrls = [];
final _picker = ImagePicker();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Social Media share plugin example'),
centerTitle: true,
),
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
physics: const ClampingScrollPhysics(),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Basic share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
var video = await _pickFile(FileType.video);
if (video != null) {
_shareVideoToFacebook(
filePath: video.paths[0],
dstPath: '/LecleSocialShareExample/Facebook/',
fileProviderPath: '.social.share.fileprovider',
);
}
},
child: const Text('Share video to facebook'),
),
ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
if (image != null) {
_sharePhotoToFacebook(
filePath: image.path,
dstPath: '/LecleSocialShareExample/Facebook/',
fileProviderPath: '.social.share.fileprovider',
);
}
},
child: const Text('Share photo to facebook'),
),
ElevatedButton(
onPressed: () {
_shareFeedContentToFacebook(
link: "https://pub.dev",
linkName: "pub",
hashtag: "flutter_pub",
);
},
child: const Text('Share feed content to facebook'),
),
ElevatedButton(
onPressed: () {
_shareLinkContentToFacebook(
contentUrl: "https://pub.dev",
);
},
child: const Text('Share link content to facebook'),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Media content share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
var videos = await _pickFile(FileType.video,
allowMultiple: Platform.isAndroid);
_shareVideoMediaContentToFacebook(
videoUrls: videos?.paths,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text('Share video media content to facebook'),
),
ElevatedButton(
onPressed: () async {
var images = await _picker.pickMultiImage();
_sharePhotoMediaContentToFacebook(
imageUrls: images?.map((image) => image.path).toList(),
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text('Share photo media content to facebook'),
),
ElevatedButton(
onPressed: () async {
imageUrls = (await _picker.pickMultiImage())
?.map((image) => image.path)
.toList();
videoUrls =
(await _pickFile(FileType.video, allowMultiple: true))
?.paths;
_shareVideoAndPhotoMediaContentToFacebook(
imageUrls: imageUrls,
videoUrls: videoUrls,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share video and photo media content to facebook'),
),
Visibility(
visible: Platform.isAndroid,
child: Column(
children: [
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Facebook story share',
style: TextStyle(fontSize: 20.0),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var image = await _picker.pickImage(
source: ImageSource.gallery);
_shareImageBackgroundAssetToFacebookStoryWithIntent(
appId: '3258588111079263',
imagePath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share image background asset to facebook story with intent'),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var video = await _picker.pickVideo(
source: ImageSource.gallery);
_shareVideoBackgroundAssetToFacebookWithIntent(
appId: '3258588111079263',
videoPath: video?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share video background asset to facebook story with intent'),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var image = await _picker.pickImage(
source: ImageSource.gallery);
_shareStickerAssetToFacebookStoryWithIntent(
appId: '3258588111079263',
stickerPath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share sticker background asset to facebook story with intent'),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Facebook story share ${Platform.isAndroid ? 'using ShareStoryContent' : ''}',
style: const TextStyle(fontSize: 20.0),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
_shareBitmapImageBackgroundAssetToFacebook(
imagePath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share bitmap image background asset to facebook story'),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
_shareImageBackgroundAssetToFacebookStory(
photoBackgroundAssetPath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share photo background asset to facebook story'),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
_shareVideoBackgroundAssetToFacebookStory(
videoBackgroundAssetPath: video?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share video background asset to facebook story'),
),
),
Visibility(
visible: Platform.isIOS,
child: ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
_shareImageBackgroundAssetToFacebookStoryiOS(
photoBackgroundAssetPath: image?.path,
appId: '3258588111079263',
);
},
child: const Text(
'Share image background asset to facebook story iOS'),
),
),
Visibility(
visible: Platform.isIOS,
child: ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
_shareVideoBackgroundAssetToFacebookStoryiOS(
videoBackgroundAssetPath: video?.path,
appId: '3258588111079263',
);
},
child: const Text(
'Share video background asset to facebook story iOS'),
),
),
Visibility(
visible: Platform.isIOS,
child: ElevatedButton(
onPressed: () async {
var sticker =
await _picker.pickImage(source: ImageSource.gallery);
_shareStickerAssetToFacebookStoryiOS(
stickerAssetPath: sticker?.path,
appId: '3258588111079263',
);
},
child:
const Text('Share sticker asset to facebook story iOS'),
),
),
Visibility(
visible: Platform.isIOS,
child: ElevatedButton(
onPressed: () async {
var images = await _picker.pickMultiImage();
var stickers = await _picker.pickMultiImage();
_shareBackgroundImageAndStickerToFacebookStoryiOS(
photoBackgroundAssetPaths:
images?.map((image) => image.path).toList(),
stickerAssetPaths:
stickers?.map((image) => image.path).toList(),
appId: '3258588111079263',
);
},
child: const Text(
'Share background image and sticker asset to facebook story iOS'),
),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Facebook reels share',
style: TextStyle(fontSize: 20.0),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
var sticker =
await _picker.pickImage(source: ImageSource.gallery);
_shareVideoToFacebookReelsWithIntent(
filePath: video?.path,
fileProviderPath: '.social.share.fileprovider',
appId: '3258588111079263',
stickerPath: sticker?.path,
);
},
child: const Text(
'Share video asset with sticker (optional) to facebook reels'),
),
),
Visibility(
visible: Platform.isIOS,
child: ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
_shareBackgroundVideoToReelsiOS(
appId: '3258588111079263',
backgroundVideoPath: video?.path,
);
},
child: const Text('Share video asset to facebook reels iOS'),
),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Instagram share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
if (video != null) {
_shareVideoToInstagram(
filePath: video.path,
fileProviderPath: '.social.share.fileprovider',
);
}
},
child: const Text('Share video to instagram'),
),
ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
if (image != null) {
_sharePhotoToInstagram(
filePath: image.path,
fileProviderPath: '.social.share.fileprovider',
);
}
},
child: const Text('Share photo to instagram'),
),
const SizedBox(height: 24.0),
],
),
),
),
);
}
Future<FilePickerResult?> _pickFile(FileType type,
{bool allowMultiple = false}) async {
switch (type) {
case FileType.image:
return await FilePicker.platform
.pickFiles(allowMultiple: allowMultiple, type: type);
case FileType.video:
return await FilePicker.platform
.pickFiles(allowMultiple: allowMultiple, type: type);
case FileType.any:
case FileType.media:
case FileType.audio:
case FileType.custom:
return null;
default:
return null;
}
}
Future<dynamic> _shareVideoToFacebook({
required String? filePath,
required String fileProviderPath,
String? dstPath,
String? contentTitle,
String? contentDescription,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
String? previewImagePath,
}) async {
return LecleSocialShare.shareVideoToFacebook(
filePath: filePath,
dstPath: dstPath,
contentTitle: contentTitle,
contentDescription: contentDescription,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
contentUrl: contentUrl,
previewImagePath: previewImagePath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _sharePhotoToFacebook({
required String? filePath,
required String fileProviderPath,
String? dstPath,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
}) async {
return LecleSocialShare.sharePhotoToFacebook(
filePath: filePath,
dstPath: dstPath,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
contentUrl: contentUrl,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareFeedContentToFacebook({
String? link,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? linkCaption,
String? linkName,
String? linkDescription,
String? mediaSource,
String? picture,
String? toId,
}) async {
return LecleSocialShare.shareFeedContentToFacebook(
link: link,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
linkCaption: linkCaption,
linkName: linkName,
linkDescription: linkDescription,
mediaSource: mediaSource,
picture: picture,
toId: toId,
);
}
Future<dynamic> _shareLinkContentToFacebook({
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
String? quote,
}) async {
return LecleSocialShare.shareLinkContentToFacebook(
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
contentUrl: contentUrl,
quote: quote,
);
}
Future<dynamic> _shareVideoMediaContentToFacebook({
required String fileProviderPath,
String? dstPath,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
List<String?>? videoUrls,
}) async {
return LecleSocialShare.shareVideoMediaContentToFacebook(
dstPath: dstPath,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
contentUrl: contentUrl,
videoUrls: videoUrls,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _sharePhotoMediaContentToFacebook({
required String fileProviderPath,
String? dstPath,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
List<String?>? imageUrls,
}) async {
return LecleSocialShare.sharePhotoMediaContentToFacebook(
dstPath: dstPath,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
contentUrl: contentUrl,
imageUrls: imageUrls,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareVideoAndPhotoMediaContentToFacebook({
required String fileProviderPath,
required List<String?>? videoUrls,
required List<String?>? imageUrls,
String? dstPath,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
}) async {
return LecleSocialShare.shareVideoAndPhotoMediaContentToFacebook(
fileProviderPath: fileProviderPath,
imageUrls: imageUrls,
videoUrls: videoUrls,
dstPath: dstPath,
contentUrl: contentUrl,
hashtag: hashtag,
placeId: placeId,
peopleIds: peopleIds,
ref: ref,
pageId: pageId,
);
}
Future<dynamic> _shareImageBackgroundAssetToFacebookStoryWithIntent({
String? imagePath,
required String appId,
required String fileProviderPath,
String? dstPath,
}) async {
return LecleSocialShare.shareImageBackgroundAssetToFacebookStoryWithIntent(
appId: appId,
imagePath: imagePath,
dstPath: dstPath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareVideoBackgroundAssetToFacebookWithIntent({
String? videoPath,
required String appId,
required String fileProviderPath,
String? dstPath,
}) async {
return LecleSocialShare.shareVideoBackgroundAssetToFacebookStoryWithIntent(
appId: appId,
videoPath: videoPath,
dstPath: dstPath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareStickerAssetToFacebookStoryWithIntent({
required String appId,
required String fileProviderPath,
String? stickerPath,
String? dstPath,
String? stickerTopBgColor,
String? stickerBottomBgColor,
}) async {
return LecleSocialShare.shareStickerAssetToFacebookStoryWithIntent(
appId: appId,
stickerPath: stickerPath,
stickerTopBgColor: stickerTopBgColor,
stickerBottomBgColor: stickerBottomBgColor,
dstPath: dstPath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareBitmapImageBackgroundAssetToFacebook({
required String fileProviderPath,
String? imagePath,
String? dstPath,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
String? attributionLink,
List<String>? backgroundColorList,
String? videoBackgroundAssetPath,
String? photoBackgroundAssetPath,
}) async {
return LecleSocialShare.shareBitmapImageBackgroundAssetToFacebookStory(
imagePath: imagePath,
dstPath: dstPath,
hashtag: hashtag,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
contentUrl: contentUrl,
attributionLink: attributionLink,
backgroundColorList: backgroundColorList,
videoBackgroundAssetPath: videoBackgroundAssetPath,
photoBackgroundAssetPath: photoBackgroundAssetPath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareImageBackgroundAssetToFacebookStory({
required String fileProviderPath,
String? dstPath,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
String? attributionLink,
List<String>? backgroundColorList,
String? photoBackgroundAssetPath,
String? stickerPath,
}) async {
return LecleSocialShare.shareImageBackgroundAssetToFacebookStory(
dstPath: dstPath,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
contentUrl: contentUrl,
attributionLink: attributionLink,
backgroundColorList: backgroundColorList,
photoBackgroundAssetPath: photoBackgroundAssetPath,
stickerPath: stickerPath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareVideoBackgroundAssetToFacebookStory({
required String fileProviderPath,
String? dstPath,
String? pageId,
String? ref,
List<String>? peopleIds,
String? placeId,
String? hashtag,
String? contentUrl,
String? attributionLink,
List<String>? backgroundColorList,
String? videoBackgroundAssetPath,
String? stickerPath,
}) async {
return LecleSocialShare.shareVideoBackgroundAssetToFacebookStory(
dstPath: dstPath,
pageId: pageId,
ref: ref,
peopleIds: peopleIds,
placeId: placeId,
hashtag: hashtag,
contentUrl: contentUrl,
attributionLink: attributionLink,
backgroundColorList: backgroundColorList,
videoBackgroundAssetPath: videoBackgroundAssetPath,
stickerPath: stickerPath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _shareVideoToFacebookReelsWithIntent({
required String? filePath,
required String appId,
required String fileProviderPath,
String? dstPath,
String? stickerPath,
String? stickerTopBgColor,
String? stickerBottomBgColor,
}) async {
return LecleSocialShare.shareVideoToFacebookReelsWithIntent(
filePath: filePath,
appId: appId,
fileProviderPath: fileProviderPath,
dstPath: dstPath,
stickerPath: stickerPath,
stickerTopBgColor: stickerTopBgColor,
stickerBottomBgColor: stickerBottomBgColor,
);
}
Future<dynamic> _shareImageBackgroundAssetToFacebookStoryiOS({
required String appId,
required String? photoBackgroundAssetPath,
}) async {
return LecleSocialShare.shareImageBackgroundAssetToFacebookStoryiOS(
appId: appId,
photoBackgroundAssetPath: photoBackgroundAssetPath,
);
}
Future<dynamic> _shareVideoBackgroundAssetToFacebookStoryiOS({
required String appId,
required String? videoBackgroundAssetPath,
}) async {
return LecleSocialShare.shareVideoBackgroundAssetToFacebookStoryiOS(
appId: appId,
videoBackgroundAssetPath: videoBackgroundAssetPath,
);
}
Future<dynamic> _shareStickerAssetToFacebookStoryiOS({
required String appId,
required String? stickerAssetPath,
List<String>? backgroundTopColor,
List<String>? backgroundBottomColor,
}) async {
return LecleSocialShare.shareStickerAssetToFacebookStoryiOS(
appId: appId,
stickerAssetPath: stickerAssetPath,
backgroundTopColor: backgroundTopColor,
backgroundBottomColor: backgroundBottomColor,
);
}
Future<dynamic> _shareBackgroundImageAndStickerToFacebookStoryiOS({
required String appId,
required List<String?>? photoBackgroundAssetPaths,
required List<String?>? stickerAssetPaths,
List<String>? backgroundTopColor,
List<String>? backgroundBottomColor,
}) async {
return LecleSocialShare.shareBackgroundImageAndStickerToFacebookStoryiOS(
appId: appId,
photoBackgroundAssetPaths: photoBackgroundAssetPaths,
stickerAssetPaths: stickerAssetPaths,
backgroundTopColor: backgroundTopColor,
backgroundBottomColor: backgroundBottomColor,
);
}
Future<dynamic> _shareBackgroundVideoToReelsiOS({
required String appId,
required String? backgroundVideoPath,
}) async {
return LecleSocialShare.shareBackgroundVideoToReelsiOS(
appId: appId,
backgroundVideoPath: backgroundVideoPath,
);
}
Future<dynamic> _shareVideoToInstagram({
required String? filePath,
required String fileProviderPath,
String? dstPath,
}) async {
LecleSocialShare.shareVideoToInstagram(
filePath: filePath,
dstPath: dstPath,
fileProviderPath: fileProviderPath,
);
}
Future<dynamic> _sharePhotoToInstagram({
required String? filePath,
required String fileProviderPath,
String? dstPath,
}) async {
LecleSocialShare.sharePhotoToInstagram(
filePath: filePath,
dstPath: dstPath,
fileProviderPath: fileProviderPath,
);
}
}