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

插件详情v4.0.0

open_file

一个插件,可以在 Flutter 中调用原生 APP 打开文件,并返回字符串结果,支持 iOS(UTI)、Android(Intent)、PC(FFI)和 Web(dart:html)

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
48.6万
喜欢数
1090
Pub 分数
160

安装插件

flutter pub add open_file

插件介绍

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

open_file 包使 Flutter 应用程序能够使用平台特定机制启动原生应用程序以打开文件。在 Android 上,它使用 Intent;在 iOS 上,它利用 UTI;在桌面平台(macOS、Windows、Linux)上,它采用 FFI;在 Web 上,它使用 dart:html。它返回一个字符串结果,指示成功或失败,使其非常适合跨平台处理 PDF、图像和文档等文件类型,且所需样板代码极少。

适合场景

  • 打开PDF文件和文档
  • 启动外部应用程序以查看文件
  • 支持文件共享工作流程
  • 跨平台文件处理
  • 与文件选择器插件集成
  • 在应用中启用文档预览

主要特点

  • 跨平台文件打开
  • 通过平台通道实现原生集成
  • 基于字符串的结果反馈
  • 支持 iOS UTI 和 Android Intent
  • 通过 FFI 支持桌面端
  • 与 dart:html 的 Web 兼容性

适合对象

  • 需要文件预览的应用
  • 文档管理工具
  • 文件选择器集成
  • 跨平台应用
  • 面向 iOS、Android、Web 和桌面端的开发者

使用建议

  • 需要正确的文件路径处理
  • 受操作系统支持的文件类型限制
  • 某些平台可能需要额外的权限
  • 结果处理取决于平台行为
  • 不适用于文件创建或编辑

原始 README

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

open_file

pub package Discord

A plug-in that can call native APP to open files with string result in flutter, support iOS(DocumentInteraction) / android(intent) / PC(ffi) / web(dart:html)

Usage

To use this plugin, add open_file as a dependency in your pubspec.yaml file.

If you want to open an external file, You need to request permission start in 3.3.0, This is an example

dependencies:
  #androidx
  open_file: ^lastVersion 
  #support
  #open_file: ^1.3.0

Example

import 'package:open_file/open_file.dart';

OpenFile.open("/sdcard/example.txt");

//Support for custom add types
const types = {
  ".pdf": "application/pdf",
  ".dwg": "application/x-autocad"
};
_openOtherTypeFile() async {
  final filePath = "/sdcard/Download/R-C.dwg";
  final extension = path.extension(filePath);//import 'package:path/path.dart' as path;
  await OpenFile.open(filePath, type: types[extension]);
}
//OpenFile.open("/sdcard/example.txt", type: "text/plain", isIOSAppOpen: true);

Support

android
{
            {".3gp",    "video/3gpp"},
            {".torrent","application/x-bittorrent"},
            {".kml",    "application/vnd.google-earth.kml+xml"},
            {".gpx",    "application/gpx+xml"},
            {".csv",    "application/vnd.ms-excel"},
            {".apk",    "application/vnd.android.package-archive"},
            {".asf",    "video/x-ms-asf"},
            {".avi",    "video/x-msvideo"},
            {".bin",    "application/octet-stream"},
            {".bmp",    "image/bmp"},
            {".c",      "text/plain"},
            {".class",  "application/octet-stream"},
            {".conf",   "text/plain"},
            {".cpp",    "text/plain"},
            {".doc",    "application/msword"},
            {".docx",   "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
            {".xls",    "application/vnd.ms-excel"},
            {".xlsx",   "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
            {".exe",    "application/octet-stream"},
            {".gif",    "image/gif"},
            {".gtar",   "application/x-gtar"},
            {".gz",     "application/x-gzip"},
            {".h",      "text/plain"},
            {".htm",    "text/html"},
            {".html",   "text/html"},
            {".jar",    "application/java-archive"},
            {".java",   "text/plain"},
            {".jpeg",   "image/jpeg"},
            {".jpg",    "image/jpeg"},
            {".js",     "application/x-javascript"},
            {".log",    "text/plain"},
            {".m3u",    "audio/x-mpegurl"},
            {".m4a",    "audio/mp4a-latm"},
            {".m4b",    "audio/mp4a-latm"},
            {".m4p",    "audio/mp4a-latm"},
            {".m4u",    "video/vnd.mpegurl"},
            {".m4v",    "video/x-m4v"},
            {".mov",    "video/quicktime"},
            {".mp2",    "audio/x-mpeg"},
            {".mp3",    "audio/x-mpeg"},
            {".mp4",    "video/mp4"},
            {".mpc",    "application/vnd.mpohun.certificate"},
            {".mpe",    "video/mpeg"},
            {".mpeg",   "video/mpeg"},
            {".mpg",    "video/mpeg"},
            {".mpg4",   "video/mp4"},
            {".mpga",   "audio/mpeg"},
            {".msg",    "application/vnd.ms-outlook"},
            {".ogg",    "audio/ogg"},
            {".pdf",    "application/pdf"},
            {".png",    "image/png"},
            {".pps",    "application/vnd.ms-powerpoint"},
            {".ppt",    "application/vnd.ms-powerpoint"},
            {".pptx",   "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
            {".prop",   "text/plain"},
            {".rc",     "text/plain"},
            {".rmvb",   "audio/x-pn-realaudio"},
            {".rtf",    "application/rtf"},
            {".sh",     "text/plain"},
            {".tar",    "application/x-tar"},
            {".tgz",    "application/x-compressed"},
            {".txt",    "text/plain"},
            {".wav",    "audio/x-wav"},
            {".wma",    "audio/x-ms-wma"},
            {".wmv",    "audio/x-ms-wmv"},
            {".wps",    "application/vnd.ms-works"},
            {".xml",    "text/plain"},
            {".z",      "application/x-compress"},
            {".zip",    "application/x-zip-compressed"},
            {"",        "*/*"}
}

when Conflict with other plugins about FileProvider, add code below in your /android/app/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="xxx.xxx.xxxxx">
    <application>
        ...
        <provider
                android:name="androidx.core.content.FileProvider"
                android:authorities="${applicationId}.fileProvider"
                android:exported="false"
                android:grantUriPermissions="true"
                tools:replace="android:authorities">
            <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/filepaths"
                    tools:replace="android:resource" />
        </provider>
    </application>
</manifest>

when Android dependency 'com.android.support:appcompat-v7' has different version for the compile error, add code below in your /android/build.gradle

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.1"
            }
        }
    }
}
IOS with UTI (DocumentInteraction Auto)
{
            {".rtf",    "public.rtf"},
            {".txt",    "public.plain-text"},
            {".html",   "public.html"},
            {".htm",    "public.html"},
            {".xml",    "public.xml"},
            {".tar",    "public.tar-archive"},
            {".gz",     "org.gnu.gnu-zip-archive"},
            {".gzip",   "org.gnu.gnu-zip-archive"},
            {".tgz",    "org.gnu.gnu-zip-tar-archive"},
            {".jpg",    "public.jpeg"},
            {".jpeg",   "public.jpeg"},
            {".png",    "public.png"},
            {".avi",    "public.avi"},
            {".mpg",    "public.mpeg"},
            {".mpeg",   "public.mpeg"},
            {".mp4",    "public.mpeg-4"},
            {".3gpp",   "public.3gpp"},
            {".3gp",    "public.3gpp"},
            {".mp3",    "public.mp3"},
            {".zip",    "com.pkware.zip-archive"},
            {".gif",    "com.compuserve.gif"},
            {".bmp",    "com.microsoft.bmp"},
            {".ico",    "com.microsoft.ico"},
            {".doc",    "com.microsoft.word.doc"},
            {".xls",    "com.microsoft.excel.xls"},
            {".ppt",    "com.microsoft.powerpoint.​ppt"},
            {".wav",    "com.microsoft.waveform-​audio"},
            {".wm",     "com.microsoft.windows-​media-wm"},
            {".wmv",    "com.microsoft.windows-​media-wmv"},
            {".pdf",    "com.adobe.pdf"}
}
MacOS

add this to the entitlements file

<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>

所属分类

依赖

依赖清单 7 项

  • open_file_android^1.1.0
  • open_file_ios^1.1.0
  • open_file_linux^1.1.0
  • open_file_mac^1.1.0
  • open_file_platform_interface^1.1.0
  • open_file_web^1.1.0
  • open_file_windows^1.1.0

源码仓库

使用此插件的项目

所在榜单