From a141cf2fc78f5abad56676cd1c684fc7806d88e2 Mon Sep 17 00:00:00 2001 From: Miguel Ruivo Date: Wed, 17 Jun 2020 22:13:44 +0100 Subject: [PATCH] Adds getDirectoryPath() desktop (go) implementation --- file_picker/CHANGELOG.md | 3 +++ file_picker/go/file_darwin.go | 8 ++++++++ file_picker/go/file_linux.go | 8 ++++++++ file_picker/go/file_unsupported.go | 4 ++++ file_picker/go/file_windows.go | 8 ++++++++ file_picker/go/plugin.go | 10 ++++++++++ file_picker/pubspec.yaml | 4 +--- 7 files changed, 42 insertions(+), 3 deletions(-) diff --git a/file_picker/CHANGELOG.md b/file_picker/CHANGELOG.md index 0d90b72..330eba9 100644 --- a/file_picker/CHANGELOG.md +++ b/file_picker/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.12.0 +Adds `getDirectoryPath()` desktop (go) implementation. + ## 1.11.0+3 Updates tearDown() call order on Android's implementation. diff --git a/file_picker/go/file_darwin.go b/file_picker/go/file_darwin.go index fa20f71..1d918aa 100644 --- a/file_picker/go/file_darwin.go +++ b/file_picker/go/file_darwin.go @@ -73,3 +73,11 @@ func fileDialog(title string, filter string) (string, error) { path := string(filepath.Separator) + filepath.Join(pathParts[1:]...) return path, nil } + +func dirDialog(title string) (string, error) { + dirPath, _, err := dlgs.File(title, `*.*`, true) + if err != nil { + return "", errors.Wrap(err, "failed to open dialog picker") + } + return dirPath, nil +} diff --git a/file_picker/go/file_linux.go b/file_picker/go/file_linux.go index bcf7a24..aebcbac 100644 --- a/file_picker/go/file_linux.go +++ b/file_picker/go/file_linux.go @@ -37,3 +37,11 @@ func fileDialog(title string, filter string) (string, error) { } return filePath, nil } + +func dirDialog(title string) (string, error) { + dirPath, _, err := dlgs.File(title, `*.*`, true) + if err != nil { + return "", errors.Wrap(err, "failed to open dialog picker") + } + return dirPath, nil +} diff --git a/file_picker/go/file_unsupported.go b/file_picker/go/file_unsupported.go index c4d86e2..9c9b5b3 100644 --- a/file_picker/go/file_unsupported.go +++ b/file_picker/go/file_unsupported.go @@ -13,3 +13,7 @@ func fileFilter(method string) (string, error) { func fileDialog(title string, filter string) (string, error) { return "", errors.New("platform unsupported") } + +func dirDialog(title string, filter string) (string, error) { + return "", errors.New("platform unsupported") +} diff --git a/file_picker/go/file_windows.go b/file_picker/go/file_windows.go index 230f27e..3a16f13 100644 --- a/file_picker/go/file_windows.go +++ b/file_picker/go/file_windows.go @@ -37,3 +37,11 @@ func fileDialog(title string, filter string) (string, error) { } return filePath, nil } + +func dirDialog(title string) (string, error) { + dirPath, _, err := dlgs.File(title, `*.*`, true) + if err != nil { + return "", errors.Wrap(err, "failed to open dialog picker") + } + return dirPath, nil +} diff --git a/file_picker/go/plugin.go b/file_picker/go/plugin.go index 7bf7acb..a9dba4d 100755 --- a/file_picker/go/plugin.go +++ b/file_picker/go/plugin.go @@ -21,7 +21,17 @@ func (p *FilePickerPlugin) InitPlugin(messenger plugin.BinaryMessenger) error { func (p *FilePickerPlugin) handleFilePicker(methodCall interface{}) (reply interface{}, err error) { method := methodCall.(plugin.MethodCall).Method + + if "dir" == method { + dirPath, err := dirDialog("Select a directory") + if err != nil { + return nil, errors.Wrap(err, "failed to open dialog picker") + } + return dirPath, nil + } + arguments := methodCall.(plugin.MethodCall).Arguments.(map[interface{}]interface{}) + var allowedExtensions []string // Parse extensions diff --git a/file_picker/pubspec.yaml b/file_picker/pubspec.yaml index cc98cc1..1378c04 100644 --- a/file_picker/pubspec.yaml +++ b/file_picker/pubspec.yaml @@ -1,7 +1,7 @@ name: file_picker description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support. homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker -version: 1.11.0+3 +version: 1.12.0 dependencies: flutter: @@ -23,5 +23,3 @@ flutter: pluginClass: FilePickerPlugin web: default_package: file_picker_web - -