From fec06c05d3102311f5589d4bfc6bcb89789e8d8d Mon Sep 17 00:00:00 2001 From: Victor Carreras <34163765+vicajilau@users.noreply.github.com> Date: Sat, 10 Oct 2026 08:05:29 +0200 Subject: [PATCH] Keep the iOS pick open when a swipe down is cancelled presentationControllerWillDismiss finished the request right away, but UIKit calls it as soon as the user starts pulling the sheet down, even if they let it spring back. The pick completed as cancelled while the picker stayed open, and the files selected afterwards were dropped because the request had already been cleared. Wait for the dismissal transition to end and only finish the request if it was not cancelled. A completed dismissal, including the fast swipe from #2021 that may never reach presentationControllerDidDismiss, still finishes the request. Without a transition coordinator it finishes right away, as before. Bumps file_picker_darwin to 2.1.4. Fixes #2243 --- packages/file_picker_darwin/CHANGELOG.md | 4 ++++ .../IOSFilePickerHandler.swift | 23 +++++++++++++++++-- packages/file_picker_darwin/pubspec.yaml | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/file_picker_darwin/CHANGELOG.md b/packages/file_picker_darwin/CHANGELOG.md index 5670db10e..73ca4543c 100644 --- a/packages/file_picker_darwin/CHANGELOG.md +++ b/packages/file_picker_darwin/CHANGELOG.md @@ -1,3 +1,7 @@ +## 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](https://github.com/vicajilau/flutter_file_picker/issues/2243) + ## 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) diff --git a/packages/file_picker_darwin/darwin/file_picker_darwin/Sources/file_picker_darwin/IOSFilePickerHandler.swift b/packages/file_picker_darwin/darwin/file_picker_darwin/Sources/file_picker_darwin/IOSFilePickerHandler.swift index aaa999f97..738c283af 100644 --- a/packages/file_picker_darwin/darwin/file_picker_darwin/Sources/file_picker_darwin/IOSFilePickerHandler.swift +++ b/packages/file_picker_darwin/darwin/file_picker_darwin/Sources/file_picker_darwin/IOSFilePickerHandler.swift @@ -189,8 +189,27 @@ final class IOSFilePickerHandler: NSObject, finishCurrentRequest(nil) } - func presentationControllerWillDismiss(_: UIPresentationController) { - finishCurrentRequest(nil) + func presentationControllerWillDismiss( + _ presentationController: UIPresentationController + ) { + // UIKit calls this as soon as the user starts pulling the sheet down, + // even if they let it spring back, so finishing right away would + // report a cancellation while the picker is still open and drop the + // later selection. Wait for the dismissal to end instead. A fast swipe + // may never reach presentationControllerDidDismiss, so this still + // finishes the request when the dismissal completes. + guard + let coordinator = presentationController.presentedViewController + .transitionCoordinator + else { + finishCurrentRequest(nil) + return + } + coordinator.animate(alongsideTransition: nil) { [weak self] context in + if !context.isCancelled { + self?.finishCurrentRequest(nil) + } + } } func presentationControllerDidDismiss( diff --git a/packages/file_picker_darwin/pubspec.yaml b/packages/file_picker_darwin/pubspec.yaml index e966def72..b7bedad3d 100644 --- a/packages/file_picker_darwin/pubspec.yaml +++ b/packages/file_picker_darwin/pubspec.yaml @@ -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.1.4 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: