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

套件詳情v4.0.5

open_app_file

一個插件,用於使用系統預設提供的應用程式開啟應用程式有權限存取的檔案。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
8550
喜歡數
30
Pub 分數
150

安裝套件

flutter pub add open_app_file

套件介紹

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

一個 Flutter 插件,可使用系統預設應用程式開啟應用程式可存取的檔案。它支援在 Android、iOS、Web、macOS、Windows 和 Linux 上跨平台啟動檔案,讓開發者能輕鬆將檔案開啟功能整合至應用程式中,無需撰寫特定平台的程式碼。此插件適用於應用程式擁有存取權限的檔案,例如應用程式目錄中的檔案或透過檔案選擇器選取的檔案。

適用情境

  • 打開下載的文件
  • 啟動影像或PDF
  • 與原生應用共享檔案
  • 整合檔案預覽
  • 啟用使用者驅動的檔案動作

主要特色

  • 跨平台相容性
  • 使用系統預設應用程式
  • 支援所有主要作業系統
  • 檔案開啟的簡單 API
  • 透過授與的權限進行安全檔案存取

適合對象

  • 檔案管理應用
  • 文件檢視器
  • 媒體播放器
  • 生產力工具
  • 需要檔案共享的應用程式

使用建議

  • 需要適當的檔案權限
  • 僅限應用可存取的檔案
  • 平台特定的行為可能有所差異
  • 不處理檔案建立
  • Web 支援取決於瀏覽器功能

原始 README

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

open_file

pub package

A plugin to open files the app has permission to access with default system-provided applications.

Supports Android, iOS, Web, Linux, macOS and Windows.

Fork info

The library is forked from open_file by crazecoder

This version:

  • does not include REQUEST_INSTALL_PACKAGES permission on Android, so cannot install .apk's
  • does not include READ_EXTERNAL_STORAGE permission on Android
  • has completely rewritten Android implementation for more robust permission checks
  • has deprecated explicit list of MIME types, UTI's, and Linux launch options
  • web implementation is changed (see below)

The main use case for the plugin is opening a generated or downloaded file with a default system application (see example).

Usage

Add open_file as a dependency in your pubspec.yaml file.

dependencies:
  open_app_file: ^lastVersion

Example

import 'package:open_app_file/open_app_file.dart';

OpenAppFile.open('/sdcard/example.txt');

// You can provide overrides for MIME type (Android) and/or UTI (iOS). This is not necessary
// in most cases, but if you know that the file extension does not match its content, you can
// help the system to provide correct response to your request.
OpenAppFile.open('/sdcard/example.abc', mimeType: 'text/plain', uti: 'public.plain-text');

Behavior on Android

While the main purpose of the plugin is opening files owned by the host app, it is possible to open any file even considering Android 11 scoped storage limitations (see official docs). The plugin will not provide any tools for requesting permissions to prevent declaring them in the Manifest for apps that don't need to handle this case. An attempt to open a file with no permissions granted will produce an appropriate result (ResultType.permissionDenied).

See more details and instructions on how to test permission conditions in the example app.

Behavior on web

Direct local file access is generally discouraged on web, therefore we chose the approach that in most cases is the most logical web alternative: imitate user clicking on an element that targets the requested file. For most files it will result in browser downloading the requested file immediately. Some file types, like images, texts, or videos might be opened directly, so the library adds target: _blank attribute to prevent user from leaving the application by accident.

The important limitation of this approach is that there's no way to check file type or availability beforehand, so on web the open call always succeeds.

Check the example app for general idea on how app-generated or remote files can be handled on web.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案