搜索插件、代码仓与 APP 分类

插件详情v1.0.2

flutter_social_content_share

此插件可分享内容至 Instagram、Facebook、电子邮件、短信和 WhatsApp 等社交媒体。该插件在 iOS 和 Android 平台上运行良好。

AndroidiOS
近 30 天下载
49
喜欢数
171
Pub 分数
140

安装插件

flutter pub add flutter_social_content_share

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,可实现跨社交媒体平台(如 Instagram、Facebook、电子邮件、短信和 WhatsApp)的内容无缝共享。专为 Android 和 iOS 设计,可简化应用中分享功能的集成,设置简单。该插件利用原生平台功能,确保可靠性能和一致的用户体验。适用于需要快速轻松地将内容分发到社交网络的应用。

适合场景

  • 分享图片和文字到社交媒体
  • 通过电子邮件或短信发送内容
  • 在应用程序中集成 WhatsApp 分享功能
  • 启用 Facebook 和 Instagram 内容共享
  • 促进用户生成内容的分发

主要特点

  • 跨平台支持(iOS 和 Android)
  • 对多个共享目标的支持
  • 用于共享文本和图片的简单API
  • 原生集成,可靠性更高
  • 轻量且易于实现

适合对象

  • 社交媒体应用
  • 内容发布工具
  • 用户参与功能
  • 具有共享需求的移动应用
  • 面向广大受众的应用

使用建议

  • Android 上需要正确的权限
  • 仅限支持的平台
  • 可能需要额外配置以支持深度链接
  • 依赖外部应用程序的可用性
  • 不支持网页平台

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_social_content_share

Flutter Plugin for sharing contents to social media.

Introduction

It supports both the platforms Android and iOS

It provides you with most of the popular sharing options. With this plugin you can share on instagram stories and facebook stories.

Usage

Android Configuration
Paste the following attribute in the manifest tag in the android/app/src/main/AndroidManifest.xml:
         `xmlns:tools="http://schemas.android.com/tools"`
For example
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                package="your package...">
Add this piece of code in the manifest/application in the android/app/src/main/AndroidManifest.xml:
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <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" />
Create a xml file named styles.xml in the app/src/main/res/values/styles.xml folder and paste this code in the file :
<string name="facebook_app_id">xxxxxxxxxx</string>
When targeting Android 11 (API level 30)

When an app targets Android 11 (API level 30) or higher and queries for information about the other apps that are installed on a device, the system filters this information by default. The limited package visibility reduces the number of apps that appear to be installed on a device, from your app's perspective. This Plugin checks if Instagram installed. Because of the above, even with Instagram installed, you will end up with "Instagram app is not installed on your device"-errors as your app is not allowed to see Instagram.

Read this for more background information: https://developer.android.com/training/package-visibility

If you are using Android Gradle plugin 4.1+, your tools should work with the new <queries> declaration. However, older versions of the Android Gradle plugin are not aware of this new element.

How to solve this

In your android/build.gradle file, apply the correct Android Gradle plugin fix, as described on https://android-developers.googleblog.com/2020/07/preparing-your-build-for-package-visibility-in-android-11.html: Change the classpath 'com.android.tools.build:gradle dependency to a dot release version that is compatible with <queries>. E.g.:

buildscript {
    ...
    dependencies {
        // classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.android.tools.build:gradle:3.5.4'
        ...
    }
}
iOS Configuration
Add this to your Info.plist to use share on instagram and facebook story
<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fbauth</string>
        <string>fbauth2</string>
        <string>fbshareextension</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>instagram</string>
        <string>instagram-stories</string>
        <string>whatsapp</string>
    </array>

  <key>NSPhotoLibraryAddUsageDescription</key>
    <string>Allow $(PRODUCT_NAME) access to your photo library to upload your profile picture?</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Allow $(PRODUCT_NAME) access to your photo library to upload your profile picture?</string>

Add this if you are using share on facebook. For this you have to create an app on https://developers.facebook.com/ and get the App ID
<key>FacebookAppID</key>
<string>xxxxxxxxxxxxxxx</string>

<key>FacebookDisplayName</key>
    <string>My App</string>
Add the below code which will help you in opening the facebook on webpage. If your facebook app is not installed in your device."xxxxxxxxxxxxxxx" represents your facebook app id.
<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>xxxxxxxxxxxxxxx</string>
            </array>
        </dict>
    </array>

shareOnInstagram
FlutterSocialContentShare.share(
        type: ShareType.instagramWithImageUrl,
        imageUrl:
            "https://post.healthline.com/wp-content/uploads/2020/09/healthy-eating-ingredients-732x549-thumbnail-732x549.jpg");
shareOnFacebook
FlutterSocialContentShare.share(
        type: ShareType.facebookWithoutImage,
        url: "https://www.apple.com",
        quote: "captions");
shareOnSMS
FlutterSocialContentShare.shareOnSMS(
    recipients: ["xxxxxx"], text: "Text appears here");

shareOnEmail
FlutterSocialContentShare.shareOnEmail(
    recipients: ["xxxx.xxx@gmail.com"],
    subject: "Subject appears here",
    body: "Body appears here",
    isHTML: true); //default isHTML: False

shareOnWhatsapp
FlutterSocialContentShare.shareOnWhatsapp(
    number: "xxxxxx", text: "Text appears here");

Example

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_social_content_share/flutter_social_content_share.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterSocialContentShare.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  /// SHARE ON FACEBOOK CALL
  shareOnFacebook() async {
    String result = await FlutterSocialContentShare.share(
        type: ShareType.facebookWithoutImage,
        url: "https://www.apple.com",
        quote: "captions");
    print(result);
  }

  /// SHARE ON INSTAGRAM CALL
  shareOnInstagram() async {
    String result = await FlutterSocialContentShare.share(
        type: ShareType.instagramWithImageUrl,
        imageUrl:
            "https://post.healthline.com/wp-content/uploads/2020/09/healthy-eating-ingredients-732x549-thumbnail-732x549.jpg");
    print(result);
  }

  /// SHARE ON WHATSAPP CALL
  shareWatsapp() async {
    String result = await FlutterSocialContentShare.shareOnWhatsapp(
        number: "xxxxxx", text: "Text appears here");
    print(result);
  }

  /// SHARE ON EMAIL CALL
  shareEmail() async {
    String result = await FlutterSocialContentShare.shareOnEmail(
        recipients: ["xxxx.xxx@gmail.com"],
        subject: "Subject appears here",
        body: "Body appears here",
        isHTML: true); //default isHTML: False
    print(result);
  }

  /// SHARE ON SMS CALL
  shareSMS() async {
    String result = await FlutterSocialContentShare.shareOnSMS(
        recipients: ["xxxxxx"], text: "Text appears here");
    print(result);
  }

  ///Build Context
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: <Widget>[
            Text('Running on: $_platformVersion\n'),
            RaisedButton(
              child: Text("Share to facebook button"),
              color: Colors.red,
              onPressed: () {
                shareOnFacebook();
              },
            ),
            RaisedButton(
              child: Text("Share to instagram button"),
              color: Colors.red,
              onPressed: () {
                shareOnInstagram();
              },
            ),
            RaisedButton(
              child: Text("Share to whatsapp button"),
              color: Colors.red,
              onPressed: () {
                shareWatsapp();
              },
            ),
            RaisedButton(
              child: Text("Share to email button"),
              color: Colors.red,
              onPressed: () {
                shareEmail();
              },
            ),
            RaisedButton(
              child: Text("Share to sms button"),
              color: Colors.red,
              onPressed: () {
                shareSMS();
              },
            ),
          ],
        ),
      ),
    );
  }
}

所属分类

源码仓库

使用此插件的项目

暂无相关数据。