搜尋套件、儲存庫與 APP 分類

套件詳情v0.4.2+2

social_share_plugin

社交分享至 Facebook 和 Instagram 的 Flutter 插件。

AndroidiOS
近 30 天下載
10
喜歡數
48
Pub 分數
150

安裝套件

flutter pub add social_share_plugin

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

social_share_plugin 是一個 Flutter 套件,可讓 Android 與 iOS 應用程式直接將內容分享至 Facebook 與 Instagram。它簡化了社群媒體分享功能的整合,讓使用者僅需少量程式碼即可分享文字、圖片或連結。該套件利用原生平台功能,確保相容性與順暢的使用者體驗。專為尋求簡單社交分享且無需複雜設定的開發者設計。此套件為開源,並於 GitHub 上維護,支援兩大主要行動平台。

適用情境

  • 分享圖片到Instagram
  • 發布連結到 Facebook
  • 在照片應用中整合社交分享
  • 啟用快速內容分發
  • 在移動應用中添加分享按鈕

主要特色

  • 原生 Android 和 iOS 支持
  • 用於分享文字和圖片的簡單API
  • 與 Facebook 和 Instagram 的直接整合
  • 開源且由社群維護
  • 輕量且易於整合

適合對象

  • 移動應用開發者
  • 社群媒體整合商
  • 內容共享功能
  • 跨平台應用,針對 Android 和 iOS
  • 需要最少第三方依賴的應用程式

使用建議

  • 需要 Facebook 和 Instagram 的原生 SDK
  • 僅限 Android 和 iOS 平台
  • 可能需要額外的權限才能存取影像
  • 依賴外部應用的可用性(例如,已安裝 Instagram)
  • 不支援除 Facebook 和 Instagram 以外的其他社交平台

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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:

For details on these requirements, see Android - Getting Started.

After you've done that, find out what your Facebook App ID is. You can find your Facebook App ID in your Facebook App's dashboard in the Facebook developer console.

Once you've got the Facebook App ID, you'll have to do couple of preparation moves.

Add permission to allow package manager query if app is installed, should be added to the manifest root tag

<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:

  • Add the Facebook SDK for iOS to your mobile development environment
  • Configure and link your Facebook app ID
  • Add your app ID, display name, and human-readable reason for photo access to your app's .plist file.

After you've done that, find out what your Facebook App ID is. You can find it out in your Facebook App's dashboard in the Facebook developer console.

Once you've got the ID, then you'll just have to copy-paste the following to your Info.plist file, before the ending </dict></plist> tags.

<your project root>/ios/Runner/Info.plist

<key>CFBundleURLTypes</key>
<array>
   <dict>
       <key>CFBundleURLSchemes</key>
       <array>
           <!--
           Replace "000000000000" with your Facebook App ID here.
           **NOTE**: The scheme needs to start with `fb` and then your ID.
           -->
           <string>fb000000000000</string>
       </array>
   </dict>
</array>

<key>FacebookAppID</key>

<!-- Replace "000000000000" with your Facebook App ID here. -->
<string>000000000000</string>
<key>FacebookDisplayName</key>

<!-- Replace "YOUR_APP_NAME" with your Facebook App name. -->
<string>YOUR_APP_NAME</string>

<key>LSApplicationQueriesSchemes</key>
<array>
   <string>instagram</string>
   <string>fbapi</string>
   <string>fb-messenger-share-api</string>
   <string>fbauth2</string>
   <string>fbshareextension</string>
   <string>twitter</string>
</array>

Congratulations! We've just finished setup!!

How do I use it?

Instagram
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 🤖

所屬分類

依賴

依賴清單 3 項

  • social_share_plugin_android^0.1.0+1
  • social_share_plugin_ios^0.1.0+1
  • social_share_plugin_platform_interface^0.1.0+1

原始碼儲存庫

使用此套件的專案

暫無相關資料。