file_picker_darwin
2.4.0Darwin (iOS and macOS) implementation of the file_picker plugin, supporting native file picking, saving, and directory selection.
Readme
File Picker for iOS and macOS
file_picker_darwin
The iOS and macOS implementation of file_picker.
Usage
This package is endorsed, which means you can simply use file_picker as normal, and the iOS and macOS implementations will be automatically included.
macOS setup
A sandboxed macOS app needs a files entitlement before the picker can return a usable path, without it every pick or save fails with an entitlement error. Add one of the following to both macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements, depending on whether your app only needs to read picked files or also needs to write to them:
Read-only access:
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
Read and write access (required for saveFile()):
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
You can also add these from Xcode, under your target's Signing & Capabilities tab, in the App Sandbox section.
initialDirectory in a sandboxed app
In a sandboxed macOS app, the open/save dialog is presented by Powerbox, a system service that brokers file access for sandboxed apps. Powerbox will only navigate to a directory your app has already been granted access to (for example, one the user previously picked, or one covered by a security-scoped bookmark). If initialDirectory points somewhere outside that scope, Powerbox silently ignores it and falls back to a default location such as ~/Documents, without any error.
This is not officially documented by Apple, but it is a widely reported limitation of App Sandbox, not something this plugin can work around: the app itself has no way to make Powerbox trust an arbitrary path it hasn't already granted. initialDirectory will only reliably take effect on macOS for locations your app already has access to.
Pick iOS media using its current representation
List<PlatformFile> files = await FilePicker.pickFiles(
type: FileType.video,
compressionQuality: 0,
darwinOptions: const DarwinOptions(
assetRepresentationMode: DarwinAssetRepresentationMode.current,
),
);
The available modes are automatic (the default), current, and
compatible. This option applies only to the iOS photo-library picker.
Non-automatic modes require compressionQuality to be 0.
Changelog
2.4.0
- On macOS,
FilePickerDarwin(viewId:)attaches the pickers to that Flutter view's window, and fails withwindow_not_foundwhen that window is closed or hidden.
2.3.4
- On macOS, the pickers now open in the window the user is in, and still open when no window is visible instead of completing with
null. #2277
2.3.3
- The
load_failederror on iOS now lists in itsdetailswhy each picked item could not be loaded. #2274
2.3.2
- Fixed picking a Live Photo on iOS copying its paired video too and leaving it in the temporary directory. Only the still image is loaded now. #2260
- Fixed picking a package document on iOS, such as an
.rtfd, returning an image from inside it. #2259 - Fixed files picked with the iOS document picker being stored twice in the temporary directory. #2261
2.3.1
- Fixed a pick on iOS where none of the picked items could be loaded completing with an empty list, as if the user had cancelled. It now throws a
PlatformExceptionwith theload_failedcode. #2248
2.3.0
- Added
DarwinPlatformFile.assetIdentifierfor media picked from the iOS photo library, and support forDarwinOptions(copyMedia: false)to skip the copy. #2245
2.2.0
- Added support for
DarwinOptions.orderedSelection. Setting it tofalserestores swipe to select in the iOS photo library picker, which ordered selection disables. #2241
2.1.4
- Fixed a partial swipe down on the iOS picker sheet completing the pick as cancelled while the picker stayed open, which dropped the files selected afterwards. #2243
2.1.3
- Fixed
saveFile()on macOS appending a second, lowercased extension to file names with a custom extension, such asj.nme2mbAllpreset. #2238
2.1.2
- Fixed
initialDirectoryhaving no effect on macOS and iOS forpickFile(),pickFiles(), andgetDirectoryPath(). #2216
2.1.1
- Fixed picking multiple items on iOS silently returning nothing.
copyToTemporaryDirectoryderived its destination from the source's file name alone, which is not unique — photos edited in the Photos app are exported under a fixed name, and Live Photos arrive as.pvtpackages. Those copies run concurrently, so colliding names raced: one item would remove the file another was still copying, bothcopyItemcalls then threw and both items were dropped by thecompactMapover the resolved results. When every item lost the race the picker called back withnil, reaching Dart as an empty list — indistinguishable from the user cancelling. Each item is now copied into its own freshly created subdirectory.
2.1.0
- Added support for UIScene on iOS.
2.0.0
- BREAKING CHANGE:
PlatformFile.length()now returnsFuture<int?>instead ofFuture<int>. Returnsnullwhen the length could not be determined (e.g. a failed disk read), instead of0, matchinglengthSync(). #2197 - Removed the native code path behind
withDataon iOS, dead since the Dart facade stopped forwarding it (file_picker12.0.0). Picked files are no longer eagerly read into memory on the platform side;PlatformFile.readAsBytes()already reads lazily on demand. #2202
1.2.0
- Added
DarwinOptions.acceptLabel, letting callers set the confirm button text (NSOpenPanel.prompt) on macOS forpickFile()/pickFiles(). Has no effect on iOS,UIDocumentPickerViewControllerhas no equivalent there. #1861
1.1.0
- Implemented
PlatformFile.lengthSync(), returning the length iOS/macOS already reports for a picked file synchronously, without doing any I/O.
1.0.4
skipEntitlementsChecks()now overrides the newFilePickerPlatform.skipEntitlementsChecks()hook instead of being called through a type test onFilePickerPlatform.instance. No behavior change on iOS or macOS.- Added
DarwinOptions.assetRepresentationModesupport on iOS, mapped toPHPickerConfiguration.preferredAssetRepresentationMode. Requestingcurrentorcompatiblelets large HEVC, HDR, or slow-motion videos skip the transcodingautomatic(the default) would otherwise require. Non-automatic modes requirecompressionQualityto be0.
1.0.3
- Fixed a regression where
PrivacyInfo.xcprivacywas never being bundled by Swift Package Manager, because SwiftPM resolves resource paths relative to the target's own directory. #2175
1.0.2
- Fixed a crash (
FileSystemException/OSError: Is a directory) when picking a Live Photo from the iOS gallery. Live Photos are saved by iOS as.pvtpackages (directories), whichloadFileRepresentation(forTypeIdentifier: UTType.item...)returned as-is; the still image contained in the package is now extracted instead. - Fixed
getDirectoryPath,pickFiles,pickFileAndDirectoryPaths, andsaveFileon macOS defaulting to the sandbox container'sDatafolder instead of the user's real home directory when noinitialDirectoryis provided and the app has App Sandbox enabled. - Fixed the Save dialog on macOS auto-selecting the file extension along with the rest of the file name, making it easy to accidentally delete the extension when renaming. The extension is now hidden by default via
NSSavePanel.isExtensionHidden. - Fixed bundle-like directories (e.g.
.app,.fcpbundle) not being selectable as files on macOS file pickers, a regression since 8.2.0.NSOpenPanel.treatsFilePackagesAsDirectoriesis now explicitly set tofalseso these are presented as selectable files, matching Finder and other native apps. - Fixed
saveFileon macOS never enforcing an extension on the destination file when the user cleared it from the suggested name.allowedExtensionsis not forwarded tosaveFileyet, so the dialog now falls back to the extension of the suggested file name. - Fixed
saveFilereturning a scheme-less, percent-encodedUrion macOS instead of a properfile://Uri, unlike Windows and Linux. - Added
FilePickerDarwin.skipEntitlementsChecks(), letting non-sandboxed macOS apps opt out of the App Sandbox entitlement checks performed before showing a dialog. This was previously only reachable through a deprecated, no-op method onFilePickerin the root package. - Fixed a brief UI freeze on macOS right when calling
pickFiles,pickFileAndDirectoryPaths,getDirectoryPath, orsaveFile. The entitlement check now runs on a background queue before the dialog is created, instead of blocking the main thread synchronously.
1.0.1
- Fixed
pickFileAndDirectoryPathsnever returning directories on iOS and macOS. It now calls the native combined file and directory picker instead of silently falling back to file only selection. - Fixed
MissingPluginExceptionon macOS by registering the event channel stream handler. - Fixed method channel handling on macOS to support all file types and actions (
any,image,video,audio,media,custom,dir,save). - Fixed
saveFileon macOS not writing the provided filebytesto the chosen location. - Added safe argument unwrapping in macOS handler to prevent runtime crashes when arguments are null.
- Added native
UTTypefile type filtering for macOS file dialogs. - Improved package description, added example, and added missing API documentation.
1.0.0
- Initial release of iOS and macOS implementation package for
file_picker.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add file_picker_darwinpubspec.yaml
name: file_picker_darwin
description: Darwin (iOS and macOS) implementation of the file_picker plugin, supporting native file picking, saving, and directory selection.
version: 2.4.0
homepage: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_darwin
repository: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_darwin
topics:
- file-picker
- ios
- macos
- darwin
resolution: workspace
environment:
sdk: ">=3.10.0 <4.0.0"
flutter: ">=3.38.0"
flutter:
plugin:
implements: file_picker
platforms:
ios:
pluginClass: FilePickerPlugin
dartPluginClass: FilePickerDarwin
sharedDarwinSource: true
macos:
pluginClass: FilePickerPlugin
dartPluginClass: FilePickerDarwin
sharedDarwinSource: true
dependencies:
flutter:
sdk: flutter
file_picker_platform_interface: ^4.2.0
cross_file: ^0.3.5+4
path: ^1.9.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | On demand | Download | 27be6ab5…332303 |
| 1.0.1 | On demand | Download | 5d87d156…fa62ef |
| 1.0.2 | On demand | Download | b505d03b…cab9ff |
| 1.0.3 | On demand | Download | bdcba9c8…2f0eae |
| 1.0.4 | On demand | Download | 6e7cae50…65bec0 |
| 1.1.0 | On demand | Download | 5c32c940…0f5251 |
| 1.2.0 | On demand | Download | 59fa5394…5d6cf6 |
| 2.0.0 | On demand | Download | da861ccc…1bc058 |
| 2.1.0 | On demand | Download | deb3ff69…4dce5d |
| 2.1.1 | On demand | Download | 3bdc8cb6…1727e2 |
| 2.1.2 | On demand | Download | 51aef9f4…250d46 |
| 2.1.3 | On demand | Download | 3df1dc8e…ab7918 |
| 2.1.4 | On demand | Download | aa8f8f44…e76496 |
| 2.2.0 | On demand | Download | cd4b60bd…a7897b |
| 2.3.0 | On demand | Download | c40e1253…23fe14 |
| 2.3.1 | On demand | Download | 576ed6c1…92f21e |
| 2.3.2 | On demand | Download | a5a48960…836589 |
| 2.3.3 | On demand | Download | ca291826…927e0e |
| 2.3.4 | On demand | Download | bd172f8d…ed7eb7 |
| 2.4.0 | Cached · Upstream SHA-256 matched | Download | 13e73143…a70d7b |
Dependencies
cross_file "^0.3.5+4"
file_picker_platform_interface "^4.2.0"
flutter {
"sdk": "flutter"
}
path "^1.9.0"