lecle_social_share 0.3.2+1 lecle_social_share: ^0.3.2+1 copied to clipboard
A Flutter project support share files to social media (Facebook, Instagram, etc.). 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) {
LecleSocialShare.F.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) {
LecleSocialShare.F.sharePhotoToFacebook(
filePath: image.path,
dstPath: '/LecleSocialShareExample/Facebook/',
fileProviderPath: '.social.share.fileprovider',
);
}
},
child: const Text('Share photo to facebook'),
),
ElevatedButton(
onPressed: () {
LecleSocialShare.F.shareFeedContentToFacebook(
link: "https://pub.dev",
linkName: "pub",
hashtag: "flutter_pub",
);
},
child: const Text('Share feed content to facebook'),
),
ElevatedButton(
onPressed: () {
LecleSocialShare.F.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);
LecleSocialShare.F.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();
LecleSocialShare.F.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;
LecleSocialShare.F.shareVideoAndPhotoMediaContentToFacebook(
imageUrls: imageUrls,
videoUrls: videoUrls,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share video and photo media content to facebook'),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Facebook story share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
LecleSocialShare.F.shareImageBackgroundAssetToFacebookStory(
appId: '3258588111079263',
imagePath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share image background asset to facebook story'),
),
ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
LecleSocialShare.F.shareVideoBackgroundAssetToFacebookStory(
appId: '3258588111079263',
videoPath: video?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share video background asset to facebook story'),
),
ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
LecleSocialShare.F.shareStickerAssetToFacebookStory(
appId: '3258588111079263',
stickerPath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share sticker background asset to facebook story'),
),
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);
LecleSocialShare.F
.shareBitmapImageBackgroundAssetToFacebookStory(
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);
LecleSocialShare.F
.shareImageBackgroundAssetContentToFacebookStory(
photoBackgroundAssetPath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text(
'Share photo background asset content to facebook story'),
),
),
Visibility(
visible: Platform.isAndroid,
child: ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
LecleSocialShare.F
.shareVideoBackgroundAssetContentToFacebookStory(
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 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: '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),
),
),
ElevatedButton(
onPressed: () async {
var sticker =
await _picker.pickImage(source: ImageSource.gallery);
var video = await _pickFile(FileType.video);
LecleSocialShare.F.shareVideoToFacebookReels(
filePath: video?.paths[0],
fileProviderPath: '.social.share.fileprovider',
appId: '3258588111079263',
stickerPath: sticker?.path,
);
},
child: const Text(
'Share video asset (and sticker on Android) to facebook reels'),
),
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) {
LecleSocialShare.I.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) {
LecleSocialShare.I.sharePhotoToInstagram(
filePath: image.path,
fileProviderPath: '.social.share.fileprovider',
);
}
},
child: const Text('Share photo to instagram'),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Messenger share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
var video =
await _picker.pickVideo(source: ImageSource.gallery);
LecleSocialShare.M.shareVideoToMessenger(
filePath: video?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text('Share video background asset to messenger'),
),
ElevatedButton(
onPressed: () async {
var image =
await _picker.pickImage(source: ImageSource.gallery);
LecleSocialShare.M.sharePhotoToMessenger(
filePath: image?.path,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text('Share photo background asset to messenger'),
),
ElevatedButton(
onPressed: () async {
LecleSocialShare.M.sendMessageToMessenger(
message: 'https://pub.dev',
quote: 'Hello world',
hashtag: '#hello',
);
},
child: const Text('Send message to messenger'),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Telegram share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
LecleSocialShare.T.sendMessageToTelegram(
message: 'Hello world',
);
},
child: const Text('Send message to Telegram'),
),
ElevatedButton(
onPressed: () async {
LecleSocialShare.T.openTelegramDirectMessage(
username: 'user_name',
);
},
child: const Text('Open Telegram direct message'),
),
ElevatedButton(
onPressed: () async {
LecleSocialShare.T.openTelegramChannelViaShareLink(
inviteLink: 'your_invite_link',
);
},
child: const Text('Open Telegram group via invite link'),
),
ElevatedButton(
onPressed: () async {
var file = await _pickFile(FileType.any);
LecleSocialShare.T.shareFileToTelegram(
filePath: file?.paths[0],
fileProviderPath: '.social.share.fileprovider',
fileType: AssetType.any,
);
},
child: const Text('Share file to Telegram'),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'WhatsApp share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
var file = await _pickFile(FileType.any);
LecleSocialShare.W.shareFileToWhatsApp(
filePath: file?.paths[0],
fileType: AssetType.pdf,
fileProviderPath: '.social.share.fileprovider',
);
},
child: const Text('Share file to WhatsApp'),
),
ElevatedButton(
onPressed: () async {
LecleSocialShare.W.sendMessageToWhatsApp(
message: 'https://pub.dev',
phoneNumber: "receiver_phone_number",
);
},
child: const Text('Send message to WhatsApp'),
),
const Padding(
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
child: Text(
'Twitter share',
style: TextStyle(fontSize: 20.0),
),
),
ElevatedButton(
onPressed: () async {
LecleSocialShare.TW.createTwitterTweet(
title: 'Hello world',
attachedUrl: "https://pub.dev",
hashtags: [
'hello',
'world',
],
via: 'abc',
related: ['twitter', 'twitterapi'],
);
},
child: const Text('Create Twitter tweet'),
),
ElevatedButton(
onPressed: () async {
var file = await _pickFile(FileType.image);
LecleSocialShare.TW.shareVideoOrPhotoToTwitter(
filePath: file?.paths[0],
fileProviderPath: '.social.share.fileprovider',
fileType: AssetType.image,
iOSConsumerKey: 'abc',
iOSSecretKey: 'xyz',
);
},
child: const Text('Share video or photo to Twitter'),
),
const SizedBox(height: 24.0),
],
),
),
),
);
}
Future<FilePickerResult?> _pickFile(FileType type,
{bool allowMultiple = false}) async {
return await FilePicker.platform
.pickFiles(allowMultiple: allowMultiple, type: type);
}
}