Skip to content

Commit

Permalink
Merge pull request #1381 from andreaszapf/#970-support-initial-direct…
Browse files Browse the repository at this point in the history
…ory-windows

#970 Support setting an initial directory in getDirectoryPath() on Windows
  • Loading branch information
Miguel Ruivo authored Mar 20, 2024
2 parents b9b7e2a + 9293e13 commit f23fdb5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/file_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?>] 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
Expand Down
25 changes: 12 additions & 13 deletions lib/src/windows/file_picker_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<COMObject>();
// 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<Pointer>();
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<Pointer<COMObject>>().value);
if (!SUCCEEDED(hr)) throw WindowsException(hr);
}

final hwndOwner = lockParentWindow ? GetForegroundWindow() : NULL;
hr = fileDialog.show(hwndOwner);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f23fdb5

Please sign in to comment.