搜索插件、代码仓与 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!

所属分类

源码仓库

使用此插件的项目