From e33c7801ed433438e018e42e434de241d8ba30c9 Mon Sep 17 00:00:00 2001 From: andreaszapf Date: Sat, 7 Oct 2023 19:22:08 +0200 Subject: [PATCH 1/4] Support initialDirectory in getDirectoryPath() on Windows To make this work some surprising Pointer casts are needed, but I verified that the created IShellItem object works (e.g., by calling getDisplayName()) and can be released without crashing. --- lib/src/windows/file_picker_windows.dart | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/src/windows/file_picker_windows.dart b/lib/src/windows/file_picker_windows.dart index 8c71e871..b854161e 100644 --- a/lib/src/windows/file_picker_windows.dart +++ b/lib/src/windows/file_picker_windows.dart @@ -116,19 +116,18 @@ class FilePickerWindows extends FilePicker { if (!SUCCEEDED(hr)) throw WindowsException(hr); free(title); - // TODO: figure out how to set the initial directory via SetDefaultFolder / SetFolder - // if (initialDirectory != null) { - // final folder = TEXT(initialDirectory); - // final riid = calloc(); - // final item = IShellItem(riid); - // final location = item.ptr; - // SHCreateItemFromParsingName(folder, nullptr, riid.cast(), item.ptr.cast()); - // hr = fileDialog.AddPlace(item.ptr, FDAP.FDAP_TOP); - // if (!SUCCEEDED(hr)) throw WindowsException(hr); - // hr = fileDialog.SetFolder(location); - // if (!SUCCEEDED(hr)) throw WindowsException(hr); - // free(folder); - // } + if (initialDirectory != null) { + final folder = TEXT(initialDirectory); + final riid = convertToIID(IID_IShellItem); + final ppv = calloc(); + hr = SHCreateItemFromParsingName(folder, nullptr, riid, ppv); + final item = IShellItem(ppv.cast()); + free(riid); + free(folder); + if (!SUCCEEDED(hr)) throw WindowsException(hr); + hr = fileDialog.setFolder(item.ptr.cast>().value); + if (!SUCCEEDED(hr)) throw WindowsException(hr); + } final hwndOwner = lockParentWindow ? GetForegroundWindow() : NULL; hr = fileDialog.show(hwndOwner); From 75b96a8ade720da816853a3783ec63a6747bc152 Mon Sep 17 00:00:00 2001 From: andreaszapf Date: Sat, 7 Oct 2023 19:51:50 +0200 Subject: [PATCH 2/4] Update documentation --- lib/src/file_picker.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/file_picker.dart b/lib/src/file_picker.dart index bd8faacf..63146cb4 100644 --- a/lib/src/file_picker.dart +++ b/lib/src/file_picker.dart @@ -140,7 +140,7 @@ abstract class FilePicker extends PlatformInterface { /// window). This parameter works only on Windows desktop. /// /// [initialDirectory] can be optionally set to an absolute path to specify - /// where the dialog should open. Only supported on Linux and macOS. + /// where the dialog should open. Only supported on Linux, macOS, and Windows. /// /// Returns a [Future] which resolves to the absolute path of the selected directory, /// if the user selected a directory. Returns `null` if the user aborted the dialog or if the From fd49162ab8d1a5c5bef10a9a6efb65db431a300b Mon Sep 17 00:00:00 2001 From: andreaszapf Date: Sat, 7 Oct 2023 19:52:38 +0200 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94d64a83..facdff9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.2.1 +### Desktop (Windows) +The `initialDirectory` parameter of `getDirectoryPath()` now works ([#970](https://github.com/miguelpruivo/flutter_file_picker/issues/970)). + ## 6.2.0 ### Android Add ability to compress images on android by specifying a compression quality value ([#735] From 9293e13b333271d64bae3dcca3c88e7e70f36b76 Mon Sep 17 00:00:00 2001 From: andreaszapf Date: Sat, 7 Oct 2023 19:53:27 +0200 Subject: [PATCH 4/4] Update package version number --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 4c9d6537..9533bc31 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker repository: https://github.com/miguelpruivo/flutter_file_picker issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues -version: 6.2.0 +version: 6.2.1 dependencies: flutter: