Windows | macOS | iOS | Android | |
---|---|---|---|---|
Pick files | ✅ | ✅ | ✅ | ✅ |
Pick a folder | ✅ | ✅ | ✅ | ✅ |
Pick a save path | ✅ | ✅ | ❌ | ❌ |
fc_file_picker_util
is based on file_selector with the following differences:
- Support picking a folder on iOS, which returns a URL.
- Picking folder on macOS returns both path and URL.
- Picking folder on Android returns an SAF Uri (which supports both internal and external storage).
- For SAF APIs on Flutter, refer to saf_stream and saf_util.
You need to add the following key to entitlements in order for macOS app to be able to access file system:
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
/// Picks a file and return a
/// [XFile](https://pub.dev/documentation/cross_file/latest/cross_file/XFile-class.html).
/// If the user cancels the picker, it returns `null`.
final file = await FcFilePickerUtil.pickFile();
/// Picks multiple files and return a list of
/// [XFile](https://pub.dev/documentation/cross_file/latest/cross_file/XFile-class.html).
/// If the user cancels the picker, it returns `null`.
final files = await FcFilePickerUtil.pickMultipleFiles();
/// Picks a folder and return a [FcFilePickerXResult].
/// If the user cancels the picker, it returns `null`.
///
/// [writePermission] is only applicable on Android.
final folder = await FcFilePickerUtil.pickFolder(writePermission: true);
The result (FilePickerXResult
) can be a URI or path depending on the platform:
- Windows: path
- macOS: both URL and path are returned
- iOS: URL
- Note: you might need to call startAccessingSecurityScopedResource to gain access to the directory on iOS.
- Android: An SAF Uri
/// Picks a save file location and return a [String] path.
/// You can optionally specify a default file name via [defaultName].
/// If the user cancels the picker, it returns `null`.
final savePath = await FcFilePickerUtil.pickSaveFile();