Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 20 additions & 2 deletions example/lib/src/file_picker_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
bool _lockParentWindow = false;
bool _userAborted = false;
bool _multiPick = false;
bool _orderedSelection = true;
bool _safPersist = false;
bool _safReadWrite = false;
bool _supportsSafOptions = false;
Expand Down Expand Up @@ -111,7 +112,10 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
lockParentWindow: _lockParentWindow,
acceptLabel: _acceptLabelFromInput(),
),
darwinOptions: DarwinOptions(acceptLabel: _acceptLabelFromInput()),
darwinOptions: DarwinOptions(
acceptLabel: _acceptLabelFromInput(),
orderedSelection: _orderedSelection,
),
androidOptions:
_androidSafOptionsFromFlags() ?? const AndroidOptions(),
);
Expand All @@ -131,7 +135,10 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
lockParentWindow: _lockParentWindow,
acceptLabel: _acceptLabelFromInput(),
),
darwinOptions: DarwinOptions(acceptLabel: _acceptLabelFromInput()),
darwinOptions: DarwinOptions(
acceptLabel: _acceptLabelFromInput(),
orderedSelection: _orderedSelection,
),
androidOptions:
_androidSafOptionsFromFlags() ?? const AndroidOptions(),
);
Expand Down Expand Up @@ -638,6 +645,17 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
value: _multiPick,
),
),
ConstrainedBox(
constraints: const BoxConstraints.tightFor(width: 400.0),
child: SwitchListTile.adaptive(
title: const Text(
'Ordered selection (iOS photo library)',
textAlign: TextAlign.left,
),
onChanged: (value) => setState(() => _orderedSelection = value),
value: _orderedSelection,
),
),
ConstrainedBox(
constraints: const BoxConstraints.tightFor(width: 400.0),
child: SwitchListTile.adaptive(
Expand Down
16 changes: 16 additions & 0 deletions packages/file_picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ compatible representation. Non-automatic modes require
`compressionQuality: 0` and only affect media selected from the iOS photo
library.

#### iOS photo-library swipe to select

```dart
List<PlatformFile> files = await FilePicker.pickFiles(
type: FileType.media,
darwinOptions: const DarwinOptions(orderedSelection: false),
);
```

By default the iOS photo library picker numbers the selected media and returns
it in the order the user selected it, which disables selecting several items
by swiping across the grid. Set `orderedSelection: false` to restore swipe to
select when the selection order does not matter. It only applies to
`FileType.image`, `FileType.video` and `FileType.media`, the types that use the
photo library picker.

#### Confirm button text

```dart
Expand Down
5 changes: 5 additions & 0 deletions packages/file_picker_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.2.0

- Added support for `DarwinOptions.orderedSelection`. Setting it to `false` restores swipe to select in the iOS photo library picker, which ordered selection disables. [#2241](https://github.com/vicajilau/flutter_file_picker/issues/2241)
- Raised the `file_picker_platform_interface` lower bound to `^4.1.0`.
Comment thread
vicajilau marked this conversation as resolved.
Outdated

## 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 @@ -18,6 +18,7 @@ final class IOSFilePickerHandler: NSObject,
private var eventSink: FlutterEventSink?
private var allowMultipleSelection = false
private var assetRepresentationMode = PHPickerConfiguration.AssetRepresentationMode.automatic
private var orderedSelection = true
private var isDirectoryPicker = false
private var isFileAndDirectoryPicker = false
private var isSaveFile = false
Expand Down Expand Up @@ -68,6 +69,7 @@ final class IOSFilePickerHandler: NSObject,
(arguments["allowMultipleSelection"] as? Bool) ?? false
assetRepresentationMode = resolveAssetRepresentationMode(
arguments["assetRepresentationMode"] as? String)
orderedSelection = (arguments["orderedSelection"] as? Bool) ?? true

switch call.method {
case "any":
Expand Down Expand Up @@ -248,7 +250,9 @@ final class IOSFilePickerHandler: NSObject,
var configuration = PHPickerConfiguration(photoLibrary: .shared())
configuration.preferredAssetRepresentationMode = assetRepresentationMode
configuration.selectionLimit = allowsMultipleSelection ? 0 : 1
if #available(iOS 15.0, *) {
// Ordered selection keeps the results in the order the user picked
// them, but disables swipe to select, so apps can opt out.
if orderedSelection, #available(iOS 15.0, *) {
configuration.selection = .ordered
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class FilePickerDarwin extends FilePickerPlatform {
'assetRepresentationMode':
darwinOptions.assetRepresentationMode.name,
'acceptLabel': darwinOptions.acceptLabel,
'orderedSelection': darwinOptions.orderedSelection,
'dialogTitle': dialogTitle,
'initialDirectory': initialDirectory,
});
Expand Down
4 changes: 2 additions & 2 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: 2.2.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 Down Expand Up @@ -31,7 +31,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
file_picker_platform_interface: ^4.0.0
file_picker_platform_interface: ^4.1.0
cross_file: ^0.3.5+4
path: ^1.9.0

Expand Down
30 changes: 30 additions & 0 deletions packages/file_picker_darwin/test/file_picker_darwin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@ void main() {
expect(receivedLabel, isNull);
});

test('pickFile and pickFiles send orderedSelection', () async {
final picker = FilePickerDarwin();
bool? received;
Comment thread
vicajilau marked this conversation as resolved.
Outdated

TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(picker.methodChannel, (call) async {
received = (call.arguments as Map)['orderedSelection'] as bool?;
return <Map<Object?, Object?>>[];
});
addTearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(picker.methodChannel, null);
});

await picker.pickFiles(type: FileType.media);
expect(received, isTrue);

await picker.pickFiles(
type: FileType.media,
darwinOptions: const DarwinOptions(orderedSelection: false),
);
expect(received, isFalse);

await picker.pickFile(
Comment thread
vicajilau marked this conversation as resolved.
type: FileType.media,
darwinOptions: const DarwinOptions(orderedSelection: false),
);
expect(received, isFalse);
});

test(
'pickFile and pickFiles send dialogTitle and initialDirectory',
() async {
Expand Down
4 changes: 4 additions & 0 deletions packages/file_picker_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.1.0

- Added `DarwinOptions.orderedSelection`, `true` by default. Set it to `false` to restore swipe to select in the iOS photo library picker. [#2241](https://github.com/vicajilau/flutter_file_picker/issues/2241)

## 4.0.0

- **BREAKING CHANGE**: `PlatformFile.length()` now returns `Future<int?>` instead of `Future<int>`, matching `lengthSync()`. `null` means the length could not be determined (e.g. a failed disk read), distinct from a genuinely empty file, which still returns `0`. Previously both cases returned `0`, with no way to tell them apart. [#2197](https://github.com/vicajilau/flutter_file_picker/issues/2197)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DarwinOptions {
const DarwinOptions({
this.assetRepresentationMode = DarwinAssetRepresentationMode.automatic,
this.acceptLabel,
this.orderedSelection = true,
});

/// The preferred representation for media selected from the iOS photo
Expand All @@ -33,6 +34,20 @@ class DarwinOptions {
/// equivalent there.
final String? acceptLabel;

/// Whether the iOS photo library picker numbers selected media and returns
/// it in the order the user selected it.
///
/// Ordered selection disables selecting several items by swiping across
/// the grid, so users have to tap each one. Set it to `false` to restore
/// swipe to select when the selection order does not matter, in which case
/// the order of the results is not guaranteed to follow the selection.
///
/// Only applies to `FileType.image`, `FileType.video` and `FileType.media`,
/// which use the photo library picker. Other types use the Files picker,
/// which has no ordered selection. Requires iOS 15 or newer and has no
/// effect on macOS.
final bool orderedSelection;

/// Throws an [ArgumentError] if this configuration conflicts with
/// [compressionQuality].
///
Expand Down
2 changes: 1 addition & 1 deletion packages/file_picker_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: file_picker_platform_interface
description: A common platform interface for the file_picker plugin, defining the shared API surface and data contracts across platforms.
version: 4.0.0
version: 4.1.0
homepage: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_platform_interface
repository: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_platform_interface
topics:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ void main() {
expect(options.acceptLabel, equals('Choose'));
});
});

group('DarwinOptions.orderedSelection', () {
test('defaults to true', () {
expect(const DarwinOptions().orderedSelection, isTrue);
});

test('can be disabled', () {
expect(
const DarwinOptions(orderedSelection: false).orderedSelection,
isFalse,
);
});
});
}
Loading