Skip to content

Forward initialDirectory and dialogTitle to native on Darwin - #2218

Merged
vicajilau merged 4 commits into
mainfrom
fix/darwin-initial-directory-not-forwarded
Sep 22, 2026
Merged

vicajilau merged 4 commits into
mainfrom
fix/darwin-initial-directory-not-forwarded

Conversation

@vicajilau

Copy link
Copy Markdown
Owner

Summary

  • pickFile(), pickFiles(), and getDirectoryPath() in file_picker_darwin accepted initialDirectory (and dialogTitle for getDirectoryPath()) but never included them in the method channel arguments map, so they never reached native code.
  • The native macOS implementation already read args["initialDirectory"]/args["dialogTitle"] correctly in all four of its handlers, it was simply never receiving them.
  • Added Dart unit tests asserting both arguments are forwarded for pickFile(), pickFiles(), and getDirectoryPath().
  • Bumped file_picker_darwin to 2.1.2 (patch, bug fix) with a changelog entry.

Fixes #2216

Test plan

  • flutter test test/file_picker_darwin_test.dart (12/12 passing, including the 2 new tests)
  • dart analyze lib test (no issues)
  • dart format applied

pickFile(), pickFiles(), and getDirectoryPath() accepted initialDirectory as a parameter but never included it in the method channel arguments, so it never reached the native macOS and iOS implementations, which already read it correctly. getDirectoryPath() sent no arguments at all, so dialogTitle was dropped too.

Fixes #2216

@navaronbracke navaronbracke left a comment

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.

LGTM, although I would also cross check Windows / Linux / Android

Comment thread packages/file_picker_darwin/test/file_picker_darwin_test.dart Outdated
Comment thread packages/file_picker_darwin/CHANGELOG.md Outdated
vicajilau and others added 2 commits September 21, 2026 09:34
Co-authored-by: Navaron Bracke <brackenavaron@gmail.com>
Co-authored-by: Navaron Bracke <brackenavaron@gmail.com>
@vicajilau

vicajilau commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner Author

Good call @navaronbracke!! I checked all three.

Windows and Linux are fine end to end. initialDirectory reaches the actual native call in both (arena.pcwstr(initialDirectory) on Windows, the D-Bus request encoding on Linux), and Windows was already confirmed working on a real machine earlier in #2216.

Android has the same Dart side gap this PR fixes for Darwin (initialDirectory/dialogTitle aren't added to the method channel arguments for pick/getDirectoryPath), but it goes further there. The native Kotlin side never reads initialDirectory for ACTION_OPEN_DOCUMENT, ACTION_OPEN_DOCUMENT_TREE, or the ACTION_GET_CONTENT variants either, only saveFile supports it today. Making it work on Android means adding native support for turning a plain path into a SAF document tree URI, not just forwarding an argument, so it's a bigger, separate piece of work rather than something this PR should take on. I'll file a follow up issue for that instead of scope creeping this one.

The native side never sets DocumentsContract.EXTRA_INITIAL_URI for ACTION_OPEN_DOCUMENT, ACTION_OPEN_DOCUMENT_TREE, or ACTION_GET_CONTENT, only saveFile honors initialDirectory today. Making it work for picking needs native support to turn a plain path into a SAF document tree URI, tracked as a future improvement rather than fixed here.
@vicajilau
vicajilau merged commit 3afce36 into main Sep 22, 2026
18 of 19 checks passed
@vicajilau
vicajilau deleted the fix/darwin-initial-directory-not-forwarded branch September 22, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

initialDirectory has no effect, dialog opens at last‑used directory instead of specified path

2 participants