file_picker_darwin 包为 Flutter 应用程序中的 iOS 和 macOS 提供原生文件选择、保存和目录选择功能。它是 file_picker 插件的平台特定实现,利用原生系统 API 来确保与 Apple 操作系统的无缝集成。这使得用户可以通过熟悉的系统对话框浏览、选择和保存文件。该包支持文件和目录操作,确保在基于 Darwin 的平台上安全高效地处理文件。
适合场景
从设备文件系统中选择文件
将文件保存到用户定义的位置
导航和选择目录
在iOS应用中集成原生文件对话框
在 macOS 桌面应用中启用文件上传
主要特点
iOS 和 macOS 上的原生文件选择器 UI
支持文件和目录选择
通过系统权限实现安全文件访问
跨平台一致性与 file_picker
内置的文件保存操作支持
适合对象
iOS应用开发者需要文件选择
macOS 桌面 Flutter 应用需要文件 I/O
处理文档导入或导出的应用程序
使用 file_picker 插件的开发者堆栈
需要原生文件系统集成的项目
使用建议
需要正确的 iOS/macOS 权限设置
仅限 Darwin 平台(iOS 和 macOS)
依赖于主文件_picker包
可能需要为沙箱环境进行额外配置
文件访问受应用沙盒策略限制
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
File Picker
A Flutter plugin that lets you use the native file explorer to pick single or multiple files, with extension filtering, directory selection, and save-file dialogs, across Android, iOS, Linux, macOS, Windows, and Web.
This repository is a Melos workspace hosting file_picker as a federated plugin: a single cross-platform API package on top of one implementation package per platform, all versioned and published independently.
Web implementation, including Wasm compilation support.
Almost all apps should only ever depend on file_picker directly. The platform packages are pulled in transitively and registered automatically by Flutter's plugin system; you only reach for one of them directly if you need a platform-specific API that isn't exposed on the shared facade (for example FilePickerDarwin.skipEntitlementsChecks() on macOS).
Quick start
dependencies:file_picker:^13.0.0
import'package:file_picker/file_picker.dart';
final file = awaitFilePicker.pickFile();
if (file != null) {
print(file.name);
print(await file.length()); // Returns Future<int?> (or use file.lengthSync())
}
See packages/file_picker/README.md for the full feature list, platform compatibility chart, and more usage examples (multiple files, extension filters, directory picking, save-file dialogs).
Migration
Upgrading to v13? See the Migrating to v13 Guide for details on PlatformFile.length() returning Future<int?> and the removal of legacy v12-deprecated parameters.
Upgrading from pre-v12? See the Migrating to v12 Guide for the federated architecture changes (FilePicker.pickFiles() returning List<PlatformFile>, platform options, and streaming).
Contributions are welcome. Please read CONTRIBUTING.md before opening a pull request, it covers testing requirements, versioning, and changelog conventions for this workspace.
To work on this repository locally:
dart pub global activate melos
melos bootstrap
melos run analyze # flutter analyze across every package
melos run test# flutter test across every package
Each package keeps its own pubspec.yaml and CHANGELOG.md and is released independently, only the package(s) you actually changed need a version bump.
Credits
file_picker was created and maintained by Miguel Ruivo, starting in 2018, growing it from a single Android/iOS plugin into the federated, cross-platform package it is today. This repository continues that work under new ownership, built entirely on the foundation of his years of effort.
Thank you, Miguel.
License
MIT, see LICENSE. Every package in this repository is released under the same license.