Flutter Plugin for sharing image to social media.
You can use it to share:
- System
support:
- Android
- iOS
add social_image_share
as a dependency in your pubspec.yaml file.
##Setup
Add "facebook app id" to the application tag of AndroidManifest.xml
<application>
...
//add this
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider[facebook_app_id]" android:exported="false" ></provider>
...
</application>
string.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Replace "123456789" with your Facebook App ID here. -->
<string name="facebook_app_id">123456789</string>
</resources>
Add below deatils in your plist file and replace "123456789" with your Facebook App ID .
<key>FacebookAppID</key>
<string>123456789</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbauth2</string>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>facebook-stories</string>
<string>whatsapp</string>
<string>twitter</string>
<string>instagram</string>
</array>
import 'package:social_image_share /social_image_share .dart';
Directory? directory ;
if (Platform.isAndroid) {
directory = await getExternalStorageDirectory();
} else {
directory = await getApplicationDocumentsDirectory();
}
String path = '${directory!.path}/' + UniqueKey().toString() + '.png';
final imagePath = await File(path).create();
await imagePath.writeAsBytes(capturedImage);
ShareUtil().shareToInstagram(imagePath: path);
Use getExternalStorageDirectory() for Android and getApplicationDocumentsDirectory() for IOS