Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDirectoryPath not open selection window #1704

Open
1 of 4 tasks
nofacer opened this issue Feb 10, 2025 · 8 comments
Open
1 of 4 tasks

getDirectoryPath not open selection window #1704

nofacer opened this issue Feb 10, 2025 · 8 comments
Labels
new issue An issue that hasn't yet been seen from the maintainer

Comments

@nofacer
Copy link

nofacer commented Feb 10, 2025

Describe the bug
await FilePicker.platform.getDirectoryPath() doesn't pop up selection window

Platform

  • Android
  • iOS
  • Web
  • Desktop

Platform OS version
MacOS 15.3
Flutter 3.27.3
Dart 3.6.1
file_picker 8.3.3

How are you picking?

Positioned(
          right: 16.0,
          bottom: 16.0,
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              if (_count > 0) ...[
                FloatingActionButton(
                  onPressed: () async {
                    print(11);
                    String? selectedDirectory =
                        await FilePicker.platform.getDirectoryPath();
                    print(selectedDirectory);
                  },
                  child: Icon(Icons.download),
                ),
                SizedBox(width: 12.0),
              ],
              FloatingActionButton(
                onPressed: () {
                  setState(() {
                    _count++;
                  });
                },
                child: Icon(Icons.refresh),
              ),
            ],
          ),
        ),

Details to reproduce the issue
You can use the code above

Error Log
No error but it just returns null without opening up selection window.

Flutter Version details

[✓] Flutter (Channel stable, 3.27.3, on macOS 15.3 24D60 darwin-arm64, locale en-CN)
    • Flutter version 3.27.3 on channel stable at /Users/posinorth/opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (3 weeks ago), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/posinorth/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/to/macos-android-setup for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2024.3.2.2)
    • IntelliJ at /Users/posinorth/Applications/IntelliJ IDEA Community Edition.app
    • Flutter plugin version 83.0.4
    • Dart plugin version 243.23654.44

[✓] VS Code (version 1.96.4)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 15.3 24D60 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 15.3 24D60 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 132.0.6834.160

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Additional context
Roll back to 8.1.7 works well.

@nofacer nofacer added the new issue An issue that hasn't yet been seen from the maintainer label Feb 10, 2025
@milesegan
Copy link

I'm seeing something similar but with 8.1.4.

@milesegan
Copy link

I think the issue is that the NSOpenPanel code needs to always be called on the main thread. When I make this change it works for me again:

  private func handleDirectorySelection(
    _ call: FlutterMethodCall, result: @escaping FlutterResult
  ) {
    Task { @MainActor in
      let dialog = NSOpenPanel()
      let args = call.arguments as! [String: Any]

      dialog.directoryURL = URL(
        fileURLWithPath: args["initialDirectory"] as? String ?? ""
      )
      dialog.showsHiddenFiles = false
      dialog.allowsMultipleSelection = false
      dialog.canChooseDirectories = true
      dialog.canChooseFiles = false

      if dialog.runModal() == NSApplication.ModalResponse.OK {
        if let url = dialog.url {
          result(url.path)
          return
        }
      }
      // User dismissed the dialog
      result(nil)
    }
  }

I can submit a PR to do this for the other functions if @miguelpruivo agrees this is the right solution.

@Zhoucheng133
Copy link

Same issue on my Mac

If I use the example code:

String? selectedDirectory = await FilePicker.platform.getDirectoryPath();

selectedDirectoryalways be null without any selection panel.

@milesegan
Copy link

@Zhoucheng133 does this fork work for you?

https://github.com/milesegan/flutter_file_picker

@Zhoucheng133
Copy link

Zhoucheng133 commented Feb 14, 2025

@Zhoucheng133 does this fork work for you?

https://github.com/milesegan/flutter_file_picker

I use previous version and it works!

file_picker: 8.1.7  # without ^

@milesegan
Copy link

@Zhoucheng133 It would be interesting to see if that branch fixes your issue because rolling back to an old version is not a long term solution.

@Zhoucheng133
Copy link

@Zhoucheng133 It would be interesting to see if that branch fixes your issue because rolling back to an old version is not a long term solution.

I have tried your fork and it does not worked as well ;w;

Image Image

@milesegan
Copy link

@Zhoucheng133 thanks for trying it. Is your app running with app sandbox enabled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new issue An issue that hasn't yet been seen from the maintainer
Projects
None yet
Development

No branches or pull requests

3 participants