miguelpruivo / flutter_file_picker

File picker plugin for Flutter, compatible with mobile (iOS & Android), Web, Desktop (Mac, Linux, Windows) platforms with Flutter Go support.
MIT License
1.36k stars 680 forks source link

Freezing on macOS M1 #957

Closed tannermeade closed 2 years ago

tannermeade commented 2 years ago

Describe the bug File picker freezes often on macOS M1 devices on v 4.3.3 (and many versions before). This issue (https://github.com/miguelpruivo/flutter_file_picker/issues/778) should be reopened or this new issue should be used to track it.

Platform

Platform OS version What version did it happen? Several versions, but confirmed on macOS 11.6 (20G165)

How are you picking?

var pickedFiles = await FilePicker.platform.pickFiles(
      type: FileType.custom,
      allowedExtensions: ['csv'],
      allowMultiple: true,
);

Details to reproduce the issue On an M1 macOS, use the FilePicker in most any way, specifically you can use multiple files and only allow CSV and it freezes often.

Error Log The app freezes. For a few seconds, the cursor stays as a click cursor until it turns to the turning beachball. Only way to stop it is to force close the app or stop the run time.

Screenshots and/or video If applicable, add screenshots or video to help explain your problem.

Flutter Version details Has happened on several channels for a long time and the last several versions of Flutter, but here is my current doctor:

[✓] Flutter (Channel stable, 2.10.0, on macOS 11.6 20G165 darwin-arm, locale en-US)
    • Flutter version 2.10.0 at /Users/tannermeade/Coding/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (3 days ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/tannermeade/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 12.5.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.63.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.25.0

[✓] VS Code (version 1.64.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.20.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 11.6 20G165 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 97.0.4692.99

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Additional context This issue has been reported several times in this issue: https://github.com/miguelpruivo/flutter_file_picker/issues/778

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 14 days with no activity.

henry2man commented 2 years ago

Hi, just my 2 cents. I'm having issues like this using both Flutter Desktop for MacOS (using a MBP M1) and Flutter Web.

In my case I've detected that first open usually works but subsequent tries freezes.

As a workaround I've implemented a Drag&Drop zone. It's not perfect but it works as a replacement.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 14 days with no activity.

philenius commented 2 years ago

@peacememories: my following answer applies to your issue #964 as well.

@tannermeade: thank you for reporting this issue and for using our issue template. As you already figured out, there's a similar issue #964.

You mentioned that your issue would be related to #778, but you're clearly describing an issue with the desktop implementation of file_picker on macOS. However, issue #778 was related to the iOS device simulator. So I think that these are different problems.

Since I don't own a physical Apple device, let alone a MacBook with M1 processor, I'm afraid that I can't help you with your reported issue. I just tried again with our latest version, file_picker works fine on the virtual device I am testing on. There are two ways how you could help yourself:

  1. You could debug our fairly simple implementation for macOS (see https://github.com/miguelpruivo/flutter_file_picker/blob/master/lib/src/file_picker_macos.dart). Basically, to open any kind of dialog on macOS, we simply execute a shell command. This is obviously not the professional approach (PRs are welcome). For instance, for opening the file picker, we execute:

    osascript -e 'choose file of type {"csv"} with multiple selections allowed'

    You can copy paste this command to a terminal to try it out. In summary, our equivalent Dart code looks like this:

    final executable = '/usr/bin/osascript';
    final arguments = [ '-e', 'choose file of type {"csv"} with multiple selections allowed' ];
    final processResult = await Process.run(executable, arguments);
    print(processResult.stdout?.toString().trim());

    If file_picker freezes while executing this shell command, then it must be related to Flutter or macOS itself. We already had the issue on Ubuntu, that Flutter had no permissions to execute the shell command (when installed via snap). In this case, the file picker dialog didn't open up at all. Your issue is different. Please keep me posted, if you debug it and find out anything.

  2. You could switch to a more professional C++ implementation that doesn't use shell commands. Google provides its own Flutter plugin file_selector and file_selector_macos. Google says that their plugin has not yet been endorsed because it is impossible to write UI tests for their plugin (same applies to file_picker).

And yes, I can confirm that the file picker dialog takes 1-2 seconds to open. At least in my case, this delay is due to using a virtualized macOS device and still I don't have to wait 3-4 seconds. Also, the dialog never freezes or crashes even if I repeat the same procedure up to five times: file-picker-macos

I'm sorry that I can't help you any further.

tannermeade commented 2 years ago

@philenius thank you for the detailed help. I haven't been able to get it to freeze with just the command. I'll have to figure out how to debug it further and your direction is helpful for that. Thank you!

swaroopmaddu commented 2 years ago

@tannermeade I'm also on M1 mac and I have the same issue sometimes. Do you have any idea how can I solve this issue.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 14 days with no activity.

jhsware commented 2 years ago

I too have run in to this issue when moving from Intel Mac to M1 Mac. It appears that this issue arises when starting the application from Flutter (VS Code). If you run the same project in Xcode there is no issue. Perhaps worth filing a bug with the Flutter team, it might not be an issue with the plugin.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

mgenware commented 2 years ago

Please stop the stale bot from closing unresolved issues. I ran into this from time to time on an M1 when doing:

FilePicker.platform.getDirectoryPath()
miguelpruivo commented 2 years ago

Please stop the stale bot from closing unresolved issues. I ran into this from time to time on an M1 when doing:

FilePicker.platform.getDirectoryPath()

@philenius answer was pretty straight forward. Neither I or him can't provide any help regarding this at the moment because seems like we both don't own M1 Macs and makes it harder to replicate or even diagnose what can be done in order to prevent/fix it.

Anyone with a M1 Mac experiencing this issue, is welcome to contribute and issue a PR with a fix for it.

oddko commented 2 years ago

M1 Pro user here, had the issue as well but it does not seem to happen anymore on the current beta channel of flutter (2.13-pre as I speak).

jhack7 commented 2 years ago

I am having this issue as well. I am amble to consistently reproduce the issue when calling getDirectoryPath if finder is open in the path to the default path of getDirectoryPath

unfortunately up to this point I haven't been able to debug the actual issue, I am still troubleshooting but I am curious to see if others are able to reproduce in a similar way

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 14 days with no activity.

FlorianGrollich commented 2 years ago

I was able to reproduce it by calling pickFiles in an onTap function of a GestureDetector. But it only freezes if the initial directory is Recents.

Another way to reproduce it is if you call the pickFiles with the onTap Function of the GestureDetector and spam click it, but that obviously does make more sense. ^^

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

sergioisair commented 2 years ago

hello, any solution for freezing?

stephane-archer commented 3 weeks ago

https://github.com/miguelpruivo/flutter_file_picker/issues/1628