romatroskin / social_share_plugin

Social Share to Facebook and Instagram Flutter plugin.
BSD 2-Clause "Simplified" License
41 stars 86 forks source link

Social Share Flutter Plugin

Puff Puff Dev Puff Puff Dev

Developed with 💙 by

Pub coverage style: very good analysis License: MIT

Social Share to Facebook and Instagram and Twitter.

Getting Started

To get things up and running, you'll have to declare a pubspec dependency in your Flutter project. Also some minimal Android & iOS specific configuration must be done, otherise your app will crash.

Open or Create your Flutte Project

See the installation instructions on pub.

Android

In addition, you need to do the following:

<uses-permission android:name="android.permission.GET_PACKAGE_SIZE"/>

Add queries as childs of manifest root tag also

<queries>
    <package android:name="com.twitter.android" />
    <package android:name="com.facebook.katana" />
    <package android:name="com.instagram.android" />
</queries>

I prefer to pass this ID to manifest throght gradle manifestPlaceholders. You can choose any way you like, just to be sure put the ID in correct places, like in example below. Put all these inside the application tag and your Facebook App ID instead of ${facebookAppId} variable

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${facebookAppId}"/>

<meta-data android:name="com.facebook.sdk.ApplicationName" android:value="${applicationName}"/>

<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="${applicationName}" />

<provider android:authorities="com.facebook.app.FacebookContentProvider${facebookAppId}" android:name="com.facebook.FacebookContentProvider" android:exported="true"/>

<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.social.share.fileprovider" android:grantUriPermissions="true" android:exported="false">
    <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
</provider>

Need to add these variables to string resources as well, i've added them from gradle with resValue.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Example</string>
    <!-- Replace "000000000000" with your Facebook App ID here. Same to the secret -->
    <string name="facebook_app_id">000000000000</string>
    <string name="facebook_client_token">00000000000000000000000000000000</string>
</resources>

And the last one is our provider paths:

\<your project root>/android/app/src/main/res/xml/provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">

    <cache-path
        name="cache_files"
        path="/"/>
</paths>

iOS

Before you add sharing to your app you need to:

FacebookAppID 000000000000 FacebookDisplayName YOUR_APP_NAME LSApplicationQueriesSchemes instagram fbapi fb-messenger-share-api fbauth2 fbshareextension twitter

Congratulations! We've just finished setup!!

## How do I use it?

### Instagram

 ```dart
 import 'package:social_share_plugin/social_share_plugin.dart';
 File file = await imagePicker.pickImage(source: ImageSource.gallery);
 await shareToFeedInstagram(path: file.path);

Facebook

 import 'package:social_share_plugin/social_share_plugin.dart';
 final file = await imagePicker.pickImage(source: ImageSource.gallery);
 await shareToFeedFacebook(path: file.path);
 await shareToFeedFacebookLink(quote: 'quote', url: 'https://flutter.dev');

Twitter

 import 'package:social_share_plugin/social_share_plugin.dart';
 await shareToTwitterLink(text: 'text', url: 'https://flutter.dev');

That's it, thank you for paying attention!

Generated by the Very Good CLI 🤖