Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ See [`packages/file_picker/README.md`](packages/file_picker/README.md) for the f

## Migration

- **Upgrading to v14?** See the [Migrating to v14 Guide](packages/file_picker/README.md#migrating-to-v14) for the `cross_file` 0.4.0 migration, the raised minimum versions and the removed web reading options.
- **Upgrading to v13?** See the [Migrating to v13 Guide](packages/file_picker/README.md#migrating-to-v13) 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](packages/file_picker/README.md#migrating-to-v12) for the federated architecture changes (`FilePicker.pickFiles()` returning `List<PlatformFile>`, platform options, and streaming).

Expand Down
14 changes: 7 additions & 7 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ publish_to: 'none'
resolution: workspace

environment:
sdk: ">=3.10.0 <4.0.0"
sdk: ">=3.11.0 <4.0.0"

formatter:
page_width: 80

dependencies:
flutter:
sdk: flutter
file_picker: ^13.0.0
android_file_picker: ^2.0.0
file_picker_darwin: ^2.0.0
file_picker_linux: ^2.0.0
file_picker_web: ^4.0.0
windows_file_picker: ^2.0.0
file_picker: ^14.0.0
android_file_picker: ^3.0.0
file_picker_darwin: ^3.0.0
file_picker_linux: ^3.0.0
file_picker_web: ^5.0.0
windows_file_picker: ^3.0.0
file: ^7.0.1

dev_dependencies:
Expand Down
6 changes: 6 additions & 0 deletions packages/file_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 14.0.0

- **BREAKING CHANGE**: Migrated to `cross_file` 0.4.0. `PlatformFile.xFile` now returns the new `XFile` API. See the [migration guide](https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker#migrating-to-v14). [#2224](https://github.com/vicajilau/flutter_file_picker/issues/2224)
- **BREAKING CHANGE**: Requires Flutter 3.41, Dart 3.11, Android SDK 24 and macOS 10.15.
- **BREAKING CHANGE**: Removed `withData`, `withReadStream` and `readSequential` from `FilePickerWebOptions`.

## 13.1.0

- Added support for UIScene on iOS.
Expand Down
25 changes: 24 additions & 1 deletion packages/file_picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,30 @@ See the [official API reference on pub.dev](https://pub.dev/documentation/file_p

### Darwin implementation notes

The iOS and macOS native implementations live under the shared Darwin source tree (`file_picker_darwin`). The iOS implementation requires iOS 14.0 or newer because it uses `PHPickerViewController` and `PHPickerResult`.
The iOS and macOS native implementations live under the shared Darwin source tree (`file_picker_darwin`). The iOS implementation requires iOS 14.0 or newer because it uses `PHPickerViewController` and `PHPickerResult`. The macOS implementation requires macOS 10.15 or newer.

## Migrating to v14

1. **Minimum Versions Raised**: Flutter 3.41, Dart 3.11, Android SDK 24 and macOS 10.15, required by `cross_file` 0.4.0.

2. **`PlatformFile.xFile` Uses `cross_file` 0.4.0**:
* `XFile.path`, `XFile.mimeType`, `XFile.saveTo()` and `XFile.fromData` no longer exist, and `XFile.name` is now `Future<String?> name()`.
* Use `PlatformFile.path`, `PlatformFile.name`, `readAsBytes()` and `readAsByteStream()` when you do not need an `XFile`. For a file system path, check for a `FileSystemXFile`:

```dart
import 'package:cross_file/cross_file.dart';

final path = switch (file.xFile) {
FileSystemXFile(:final path) => path,
_ => null,
};
```
* See the [`cross_file` changelog](https://pub.dev/packages/cross_file/changelog) for the full list.

3. **Web Reading Options Removed**:
* `withData`, `withReadStream` and `readSequential` are removed from `FilePickerWebOptions`. Picked files are no longer read at pick time, and `readAsBytes()`/`readAsByteStream()` read them on demand.
* **v13**: `FilePickerWebOptions(withData: false, withReadStream: true, cancelUploadOnWindowBlur: false)`
* **v14**: `FilePickerWebOptions(cancelUploadOnWindowBlur: false)`

## Migrating to v13

Expand Down
20 changes: 10 additions & 10 deletions packages/file_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ topics:
- storage
- desktop
- web
version: 13.1.0
version: 14.0.0

resolution: workspace

environment:
sdk: ">=3.10.0 <4.0.0"
flutter: ">=3.38.0"
sdk: ">=3.11.0 <4.0.0"
flutter: ">=3.41.0"

dependencies:
flutter:
sdk: flutter

file_picker_platform_interface: ^4.0.0
android_file_picker: ^2.0.0
file_picker_darwin: ^2.1.0
file_picker_linux: ^2.0.0
windows_file_picker: ^2.0.0
file_picker_web: ^4.0.0
cross_file: ^0.3.5+4
file_picker_platform_interface: ^5.0.0
android_file_picker: ^3.0.0
file_picker_darwin: ^3.0.0
file_picker_linux: ^3.0.0
windows_file_picker: ^3.0.0
file_picker_web: ^5.0.0
cross_file: ^0.4.0

dev_dependencies:
flutter_test:
Expand Down
2 changes: 1 addition & 1 deletion packages/file_picker/test/file_picker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ base class TestPlatformFile extends PlatformFile {
final Uri uri;

@override
XFile get xFile => XFile(path ?? '');
XFile get xFile => XFile.fileSystem(path: path ?? '');

@override
int? lengthSync() => 100;
Expand Down
4 changes: 4 additions & 0 deletions packages/file_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.0

- **BREAKING CHANGE**: Migrated to `cross_file` 0.4.0. `PlatformFile.xFile` now returns the new `XFile` API. Requires Flutter 3.41, Dart 3.11 and Android SDK 24. [#2224](https://github.com/vicajilau/flutter_file_picker/issues/2224)

## 2.0.1

- Fixed `pickFileAndDirectoryPaths()` returning percent-encoded paths that do not exist. [#2225](https://github.com/vicajilau/flutter_file_picker/issues/2225)
Expand Down
2 changes: 1 addition & 1 deletion packages/file_picker_android/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ configure<LibraryExtension> {
namespace = "com.mr.flutter.plugin.filepicker"

defaultConfig {
minSdk = 21
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
16 changes: 7 additions & 9 deletions packages/file_picker_android/lib/src/android_platform_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ base class AndroidPlatformFile extends PlatformFile {
name: name,
uri: uri,
safHandle: safHandle,
xFile: path.isNotEmpty ? XFile(path, name: name) : null,
bytesLength: data['size'] as int?,
);
}
Expand All @@ -68,15 +67,14 @@ base class AndroidPlatformFile extends PlatformFile {
final XFile? _xFile;
final int? _bytesLength;

/// A [FileSystemXFile] for a picked file cached on disk, or a
/// [ScopedStorageXFile] for a Storage Access Framework `content://` URI.
@override
XFile get xFile {
final file = _xFile;
if (file != null) return file;
if (uri.scheme == 'file') {
return XFile(uri.toFilePath(), name: name);
}
return XFile(uri.toString(), name: name);
}
XFile get xFile =>
_xFile ??
(uri.scheme == 'file'
? XFile.fileSystem(path: uri.toFilePath())
: XFile.scopedStorage(uri: uri.toString()));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter one is a content URI, right?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly! Anything outside the file scheme is a Storage Access Framework content:// URI. I documented it on the getter in 476d9a4 so it doesn't need explaining again 🙂


/// The size Android already reported for this file when it was picked.
@override
Expand Down
11 changes: 6 additions & 5 deletions packages/file_picker_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: android_file_picker
description: Android implementation of the file_picker plugin, supporting file picking, saving, and Storage Access Framework (SAF) URI grants.
version: 2.0.1
version: 3.0.0
homepage: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_android
repository: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_android
topics:
Expand All @@ -10,8 +10,8 @@ topics:
resolution: workspace

environment:
sdk: ">=3.10.0 <4.0.0"
flutter: ">=3.38.0"
sdk: ">=3.11.0 <4.0.0"
flutter: ">=3.41.0"

flutter:
plugin:
Expand All @@ -25,11 +25,12 @@ flutter:
dependencies:
flutter:
sdk: flutter
file_picker_platform_interface: ^4.0.0
cross_file: ^0.3.5+4
file_picker_platform_interface: ^5.0.0
cross_file: ^0.4.0
path: ^1.9.0

dev_dependencies:
cross_file_io: ^1.0.0
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
38 changes: 38 additions & 0 deletions packages/file_picker_android/test/platform_file_read_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:convert';
import 'dart:io';

import 'package:cross_file/cross_file.dart';
import 'package:cross_file_io/cross_file_io.dart';
import 'package:android_file_picker/android_file_picker.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
late Directory dir;
late String path;

setUpAll(CrossFileIO.registerWith);

setUp(() {
dir = Directory.systemTemp.createTempSync('file_picker_test');
path = '${dir.path}${Platform.pathSeparator}notes.txt';
File(path).writeAsStringSync('hello file_picker');
});

tearDown(() => dir.deleteSync(recursive: true));

test('reads a picked file through cross_file', () async {
final file = AndroidPlatformFile.fromMap({
'path': path,
'name': 'notes.txt',
});

expect(file.xFile, isA<FileSystemXFile>());
expect((file.xFile as FileSystemXFile).path, path);
expect(utf8.decode(await file.readAsBytes()), 'hello file_picker');
expect(
utf8.decode(await file.readAsByteStream().expand((c) => c).toList()),
'hello file_picker',
);
expect(await file.length(), 17);
});
}
4 changes: 4 additions & 0 deletions packages/file_picker_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.0

- **BREAKING CHANGE**: Migrated to `cross_file` 0.4.0. `PlatformFile.xFile` now returns the new `XFile` API. Requires Flutter 3.41, Dart 3.11 and macOS 10.15. [#2224](https://github.com/vicajilau/flutter_file_picker/issues/2224)

## 2.1.3

- Fixed `saveFile()` on macOS appending a second, lowercased extension to file names with a custom extension, such as `j.nme2mbAllpreset`. [#2238](https://github.com/vicajilau/flutter_file_picker/issues/2238)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ iOS and macOS implementation of file_picker plugin
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.ios.deployment_target = '14.0'
s.osx.deployment_target = '10.13'
s.osx.deployment_target = '10.15'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
name: "file_picker_darwin",
platforms: [
.iOS("14.0"),
.macOS("10.13")
.macOS("10.15")
],
products: [
.library(name: "file-picker-darwin", targets: ["file_picker_darwin"])
Expand Down
14 changes: 5 additions & 9 deletions packages/file_picker_darwin/lib/src/darwin_platform_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ base class DarwinPlatformFile extends PlatformFile {
return DarwinPlatformFile(
name: name,
uri: uri,
xFile: path.isNotEmpty ? XFile(path, name: name) : null,
bytesLength: data['size'] as int?,
);
}
Expand All @@ -55,14 +54,11 @@ base class DarwinPlatformFile extends PlatformFile {
final int? _bytesLength;

@override
XFile get xFile {
final file = _xFile;
if (file != null) return file;
if (uri.scheme == 'file') {
return XFile(uri.toFilePath(), name: name);
}
return XFile(uri.toString(), name: name);
}
XFile get xFile =>
_xFile ??
(uri.scheme == 'file'
? XFile.fileSystem(path: uri.toFilePath())
: XFile.scopedStorage(uri: uri.toString()));

/// The size iOS/macOS already reported for this file when it was picked.
@override
Expand Down
11 changes: 6 additions & 5 deletions packages/file_picker_darwin/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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.1.3
version: 3.0.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:
Expand All @@ -12,8 +12,8 @@ topics:
resolution: workspace

environment:
sdk: ">=3.10.0 <4.0.0"
flutter: ">=3.38.0"
sdk: ">=3.11.0 <4.0.0"
flutter: ">=3.41.0"

flutter:
plugin:
Expand All @@ -31,11 +31,12 @@ flutter:
dependencies:
flutter:
sdk: flutter
file_picker_platform_interface: ^4.0.0
cross_file: ^0.3.5+4
file_picker_platform_interface: ^5.0.0
cross_file: ^0.4.0
path: ^1.9.0

dev_dependencies:
cross_file_io: ^1.0.0
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
38 changes: 38 additions & 0 deletions packages/file_picker_darwin/test/platform_file_read_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:convert';
import 'dart:io';

import 'package:cross_file/cross_file.dart';
import 'package:cross_file_io/cross_file_io.dart';
import 'package:file_picker_darwin/file_picker_darwin.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
late Directory dir;
late String path;

setUpAll(CrossFileIO.registerWith);

setUp(() {
dir = Directory.systemTemp.createTempSync('file_picker_test');
path = '${dir.path}${Platform.pathSeparator}notes.txt';
File(path).writeAsStringSync('hello file_picker');
});

tearDown(() => dir.deleteSync(recursive: true));

test('reads a picked file through cross_file', () async {
final file = DarwinPlatformFile.fromMap({
'path': path,
'name': 'notes.txt',
});

expect(file.xFile, isA<FileSystemXFile>());
expect((file.xFile as FileSystemXFile).path, path);
expect(utf8.decode(await file.readAsBytes()), 'hello file_picker');
expect(
utf8.decode(await file.readAsByteStream().expand((c) => c).toList()),
'hello file_picker',
);
expect(await file.length(), 17);
});
}
5 changes: 5 additions & 0 deletions packages/file_picker_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.0.0

- **BREAKING CHANGE**: Migrated to `cross_file` 0.4.0. `PlatformFile.xFile` now returns the new `XFile` API. Requires Flutter 3.41 and Dart 3.11. [#2224](https://github.com/vicajilau/flutter_file_picker/issues/2224)
- **BREAKING CHANGE**: Removed the unused `bytes` parameter of `LinuxPlatformFile.fromPath()`.

## 2.0.2

- Fixed `pickFileAndDirectoryPaths()` returning percent-encoded paths that do not exist. [#2225](https://github.com/vicajilau/flutter_file_picker/issues/2225)
Expand Down
Loading
Loading