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

flutter_share 封面
套件詳情v2.0.0

flutter_share

在您的 Flutter 應用中,簡單地在 Android 和 iOS 上分享訊息、連結或檔案(按 Enter 查看一些 GIF 動圖)。

AndroidiOS
近 30 天下載
2770
喜歡數
306
Pub 分數
150

安裝套件

flutter pub add flutter_share

套件介紹

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

Flutter Share 是一個輕量級的 Flutter 套件,可讓 Android 與 iOS 應用程式輕鬆分享訊息、連結與檔案。它提供簡單的 API 來整合原生分享意圖,讓使用者能透過系統對話框分享內容。此套件支援文字與檔案分享,非常適合需要快速分享功能的應用程式。僅需透過 pub add 進行最少設定,即可跨平台運作,無需撰寫特定於平台的程式碼。原始碼開放於 GitHub,鼓勵透明度與社群貢獻。

適用情境

  • 在社交媒體上分享連結
  • 發送文字片段到訊息應用
  • 匯出圖像或文件等檔案
  • 啟用使用者產生內容分享
  • 與應用的社交功能整合

主要特色

  • 跨平台支援(Android 與 iOS)
  • 用於分享文字和檔案的簡單 API
  • 原生共享對話框
  • 開源,擁有 GitHub 倉庫
  • 最小配置要求

適合對象

  • 需要基本共享功能的應用
  • 社交或內容分享應用
  • 檔案管理或生產力工具
  • 尋求簡單整合的開發者
  • 優先考慮簡單性和可靠性的專案

使用建議

  • 僅限 Android 和 iOS 平台
  • 需要使用者互動以進行分享
  • 沒有高級自定義選項
  • 依賴原生作業系統共享機制
  • 不支援直接分享至特定應用

原始 README

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

Share Plugin

pub package

** This plugin was discontinued after the flutter official one add support to files **

A Flutter plugin for IOS and Android providing a simple way to share a message, link or local files.

Features:

  • Share messages and/or link urls.
  • Share local files.

android         ios

Installation

First, add flutter_share as a dependency in your pubspec.yaml file.

iOS

Add if not exists one row to the ios/podfile after target runner:

...

target 'Runner' do
    use_frameworks!

...
Android

If you pretends to use the file share, you need to configure the file provider, this will give access to the files turning possible to share 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/provider_paths"/>
</provider>
</application>

Obs: You can change the android:name if you have an extension of file provider.

Add res/xml/provider_paths.xml:

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

If you want to learn more about file provider you can access:

  • https://developer.android.com/reference/android/support/v4/content/FileProvider
Example

Here is an example flutter app displaying the two shares methods. (I'm using documents_picker just to get a local file you don't need to use.)

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

import 'package:flutter/services.dart';
import 'package:flutter_share/flutter_share.dart';
import 'package:documents_picker/documents_picker.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  Future<void> share() async {
    await FlutterShare.share(
      title: 'Example share',
      text: 'Example share text',
      linkUrl: 'https://flutter.dev/',
      chooserTitle: 'Example Chooser Title'
    );
  }

  Future<void> shareFile() async {
    List<dynamic> docs = await DocumentsPicker.pickDocuments;
    if (docs == null || docs.isEmpty) return null;

    await FlutterShare.shareFile(
      title: 'Example share',
      text: 'Example share text',
      filePath: docs[0] as String,
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              FlatButton(
                child: Text('Share text and link'),
                onPressed: share,
              ),
              FlatButton(
                child: Text('Share local file'),
                onPressed: shareFile,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Feedback welcome and Pull Requests are most welcome!

所屬分類

原始碼儲存庫

使用此套件的專案