Flutter Plugin for sharing contents to social media.
You can use it share to Facebook , Instagram , WhatsApp(WhatsAppBusiness) , Twitter, Telegram,Sms,Mails And System Share UI. Support Url and Text.
support:
- Android & iOS : Facebook,WhatsApp(WhatsAppBusiness),Twitter,Instagram,System Share,Sms,Mails
Note: This plugin is still under development, and some APIs might not be available yet.
Feedback and Pull Requests are most welcome!
add flutter_social_share_plugin
as a dependency in your pubspec.yaml file.
Please check the latest version before installation.
dependencies:
flutter:
sdk: flutter
# add flutter_social_share_plugin
flutter_social_share_plugin: ^2.1.1
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" />
</application>
string.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Replace "343254889799245" with your Facebook App ID here. -->
<string name="facebook_app_id">343254889799245</string>
</resources>
Make sure you add whatsapp in AndroidManifest.xml.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<queries>
<package android:name="com.whatsapp" />
</queries>
...
</manifest>
Make sure you add SMS in AndroidManifest.xml.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<uses-permission android:name="android.permission.SEND_SMS" />
...
</manifest>
Make sure you add SMS in AndroidManifest.xml.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
...
</application>
...
</manifest>
make sure you add below deatils in your plist file.
<key>FacebookAppID</key>
<string>fbid</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb-your-fb-id</string>
</array>
</dict>
</array>
Note-: Make sure you add fb in at start of your fb Id in CFBundleURLSchemes.
Add below value in url scheme(Refer to example).
<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>tg</string>
</array>
Make sure you add whatsapp in plist.
<array>
<string>whatsapp</string>
</array>
<array>
<string>twitter</string>
</array>
<array>
<string>sms</string>
</array>
import 'package:flutter_social_share_plugin/flutter_social_share_plugin.dart';
These methods will return "success" if they successfully jump to the corresponding app.
Parameter | Description |
---|---|
String msg | Text message |
String url | Url url |
String imagePath | The local path of the image |
String mailBody | Text mail Body |
String mailSubject | Text Mail subject |
List mailRecipients | List of string for mail recipients |
Container(
width: double.infinity,
child: Column(
children: <Widget>[
const SizedBox(height: 30),
ElevatedButton(onPressed: pickImage, child: Text('Pick Image')),
ElevatedButton(onPressed: pickVideo, child: Text('Pick Video')),
ElevatedButton(
onPressed: () => onButtonTap(Share.twitter),
child: const Text('share to twitter')),
ElevatedButton(
onPressed: () => onButtonTap(Share.whatsapp),
child: const Text('share to WhatsApp'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.whatsapp_business),
child: const Text('share to WhatsApp Business'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.facebook),
child: const Text('share to FaceBook'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.share_instagram),
child: const Text('share to Instagram'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.share_telegram),
child: const Text('share to Telegram'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.share_system),
child: const Text('share to System'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.share_sms),
child: const Text('share to sms'),
),
ElevatedButton(
onPressed: () => onButtonTap(Share.share_mail),
child: const Text('share to mail'),
),
],
),
),