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

套件詳情v1.0.4

akvelon_flutter_share_plugin

一個 Flutter 插件,可透過平台的分享對話方塊從您的 Flutter 應用程式分享文字、媒體和檔案。

近 30 天下載
73
喜歡數
28
Pub 分數
35

安裝套件

flutter pub add akvelon_flutter_share_plugin

套件介紹

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

一個 Flutter 插件,可讓你的應用透過平台原生的分享對話框分享文字、媒體與檔案。它提供簡單且跨平台的介面,可將分享功能順暢地整合至 Flutter 應用程式中。該插件利用 Android 與 iOS 上的原生分享 API,確保在各裝置上行為一致。支援分享純文字、圖片與檔案,非常適合需要使用者驅動內容傳播的應用。原始碼公開於 GitHub,以確保透明度並支援自訂。

適用情境

  • 在應用程式內分享文字片段
  • 發送圖片到社群媒體或訊息應用
  • 分發檔案,如PDF或文件
  • 啟用使用者與聯絡人分享內容
  • 在跨平台應用中整合原生分享功能

主要特色

  • 跨平台共享支援
  • 用於分享文字和媒體的簡單 API
  • 檔案共享支援
  • 使用原生平台共享對話框
  • 開源並公開託管在 GitHub 上

適合對象

  • 開發跨平台應用的開發者
  • 需要內容共享功能的應用程式
  • 需要與原生共享整合的項目
  • 希望程式碼透明且可自訂的團隊
  • 針對 Android 和 iOS 的行動應用程式

使用建議

  • 需要平台特定的權限才能共享檔案
  • 僅限基本分享功能
  • 除了原生分享表單外,沒有內建的UI元件
  • 取決於分享意圖的平台可用性
  • 可能需要對大檔案進行額外處理

原始 README

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

Flutter Share Plugin

A Flutter plugin for both iOS and Android that provides ability to share plain text, links and local files. Multiple file share is also supported.

Screenshots

Click to see how it works

Installation

In the beginning, please add flutter_share_plugin as a dependency in your pubspec.yaml file.

iOS

Make sure that this row exists in your ios/podfile file after target runner:

...

target 'Runner' do
    use_frameworks!

...
Android

Please note that if you want to share files, you need to setup a FileProvider which will give access to the files for sharing with other applications.

Add to AndroidManifest.xml:

<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_provider_paths"/>
</provider>
</application>
...

Add res/xml/file_provider_paths.xml:

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

For full document about FileProvider please refer to the Android documentation.

Usage

Here is an example of flutter app sharing text, images and files:

...

            RaisedButton(
                onPressed: () {
                  FlutterSharePlugin.shareText("Here is how it works",
                      title: "share text title",
                      subject: "share text subject",
                      url: "https://pub.dev/");
                },
                child: Text("share text"),
              ),
              RaisedButton(
                onPressed: () async {
                  PickedFile f =
                      await picker.getImage(source: ImageSource.gallery);
                  if (f != null) {
                    FlutterSharePlugin.shareSingle(f.path, ShareType.IMAGE,
                        title: "share image title",
                        subject: "share image subject");
                  }
                },
                child: Text("share image"),
              ),
              RaisedButton(
                onPressed: () async {
                  PickedFile f =
                      await picker.getVideo(source: ImageSource.gallery);
                  if (f != null) {
                    FlutterSharePlugin.shareSingle(
                      f.path,
                      ShareType.VIDEO,
                      title: "share video title",
                      subject: "share video subject",
                    );
                  }
                },
                child: Text("share video"),
              ),
              RaisedButton(
                onPressed: () {
                  _shareStorageFile();
                },
                child: Text("share file"),
              ),
              RaisedButton(
                onPressed: () {
                  _shareMultipleImages();
                },
                child: Text("share multiple images"),
              ),
            ],
          ),
        ),
      ),
    ),
  );
}

  ///share the storage file
  _shareStorageFile() async {
    Directory dir = Platform.isAndroid
        ? await getExternalStorageDirectory()
        : await getApplicationDocumentsDirectory();
    File testFile = File("${dir.path}/flutter/test.txt");
    if (!await testFile.exists()) {
      await testFile.create(recursive: true);
      testFile.writeAsStringSync("test for share documents file");
    }
    FlutterSharePlugin.shareSingle(
      testFile.path,
      ShareType.FILE,
      title: "share file title",
      subject: "share file subject",
    );
  }

  ///share multiple images
  _shareMultipleImages() async {
    List<Asset> assetList = await MultiImagePicker.pickImages(maxImages: 5);
    var imageList = List<String>();
    for (var asset in assetList) {
      String path =
          await _writeByteToImageFile(await asset.getByteData(quality: 30));
      imageList.add(path);
    }
    FlutterSharePlugin.shareMultiple(
      imageList,
      ShareType.IMAGE,
      title: "share multiple images title",
      subject: "share multiple images subject",
    );
  }

  Future<String> _writeByteToImageFile(ByteData byteData) async {
    Directory dir = Platform.isAndroid
        ? await getExternalStorageDirectory()
        : await getApplicationDocumentsDirectory();
    File imageFile = new File(
        "${dir.path}/flutter/${DateTime.now().millisecondsSinceEpoch}.png");
    imageFile.createSync(recursive: true);
    imageFile.writeAsBytesSync(byteData.buffer.asUint8List(0));
    return imageFile.path;
  }
}

If you have any troubles, please, create an issue

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。