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

套件詳情v5.2.3

flutter_document_picker

允許使用者選擇文件。選取的文件會複製到應用程式的暫存目錄中。可選擇僅允許選擇特定副檔名的文件。

AndroidiOS
近 30 天下載
1.9萬
喜歡數
52
Pub 分數
150

安裝套件

flutter pub add flutter_document_picker

套件介紹

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

一個 Flutter 套件,讓使用者能從裝置的檔案系統中選擇文件。所選文件會自動複製到應用程式的暫存目錄中,以確保安全存取。支援依特定副檔名過濾檔案,提升針對性檔案選擇的易用性。可在 Android 與 iOS 上使用,並與原生檔案選擇器無縫整合。適合需要上傳或匯入文件但不需要直接存取檔案系統的應用程式。

適用情境

  • 表單中的文件上傳
  • 匯入使用者產生的檔案
  • 應用間檔案共享
  • 讀取外部設定檔
  • 支援文件導向的工作流程

主要特色

  • 選擇具有副檔名過濾的文件
  • 自動將檔案複製到暫存目錄
  • 跨平台(Android & iOS)
  • 簡單的 API 結合
  • 安全的暫時檔案處理

適合對象

  • 需要檔案輸入的應用程式
  • 文件管理功能
  • 使用者驅動的檔案匯入
  • 移動數據採集工具
  • 注重隱私的檔案存取

使用建議

  • 檔案被複製到暫存儲存
  • 僅限支援的檔案類型
  • 需要平台特定權限
  • 暫時檔案可能會在應用程式重新啟動時被刪除
  • 無法直接存取原始檔案路徑

原始 README

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

flutter_document_picker

Allows user pick a document. Picked document is copied to app temporary directory. Optionally allows pick document with specific extension only.

When file is picked its extension is checked using allowedFileExtensions parameter. Then file is copied to app temp directory. Copied file path is returned as result. If picked file extension is not in allowedFileExtensions list then extension_mismatch error is returned.

In Android Intent.ACTION_OPEN_DOCUMENT is used. This intent is supported only from Android 19 (KitKat) SDK version. So this plugin can be used only if app minSdkVersion is 19 or more.

In iOS UIDocumentPickerViewController is used. Files can be filtered by list of UTI types using allowedUtiTypes parameter. Picked file path is returned as result.

Params

Plugin has 3 optional parameters to help pick only specific document type:

  • List<String> allowedUtiTypes (used only in iOS)

    In iOS Uniform Type Identifiers is used to check document types. If list is null or empty "public.data" document type will be provided. Only documents with provided UTI types will be enabled in iOS document picker.

    More info: https://developer.apple.com/library/archive/qa/qa1587/_index.html

  • List<String> allowedFileExtensions (used both in iOS and in Android)

    List of file extensions that picked file should have. If list is null or empty - picked document extension will not be checked.

  • List<String> allowedMimeTypes (used only in Android)

    Only files with provided MIME types will be shown in document picker. If list is null or empty - */* MIME type will be used.

  • List<String> invalidFileNameSymbols (used both in iOS and in Android)

    List symbols that will be sanitized to "_" in the selected document name. I.e. Google Drive allows symbol '/' in the document name, but this symbol is not allowed in file name that will be saved locally.

    Default list: ['/'].

    Example: file name 'Report_2018/12/08.txt' will be replaced to 'Report_2018_12_08.txt'

Example

//Without parameters:
final path = await FlutterDocumentPicker.openDocument();
  
  ...

    
//With parameters:
FlutterDocumentPickerParams params = FlutterDocumentPickerParams(      
  allowedFileExtensions: ['mwfbak'],
  allowedUtiTypes: ['com.sidlatau.example.mwfbak'],
  allowedMimeTypes: ['application/*'],
  invalidFileNameSymbols: ['/'],
);

final path = await FlutterDocumentPicker.openDocument(params: params);

//Pick multiple files:
final paths = await FlutterDocumentPicker.openDocuments(params: params);

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。