パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。