flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

desktop_drop 0.5.0 - Web doesn not receive image, instead, browser opens the file in a new tab

Open Eerey opened this issue 1 year ago • 1 comments

When an image is dragged from the file system (Windows, Desktop Explorer) to web (Flutter with CanvasKit), the DropTarget does not trigger and the image is opened in a new tab.

Tested in Chrome and Firefox (most recent update).

Eerey avatar Sep 23 '24 10:09 Eerey

In Windows, while debugging on Chrome, the behaviour is the expected one. On the release version (Flutter with CanvasKIT) accessed through a server, the browser (Chrome and Opera GX) blocks the behaviour so the dropped files are simply downloaded or opened (if the browser can open them).

You can solve this by disabling the default behaviour from the browsers. I did this by adding this lines on web/index.html, inside the

tag.
<script>
      document.addEventListener('dragover', function(event) {
        event.preventDefault();
      }, false);

      document.addEventListener('drop', function(event) {
        event.preventDefault();
      }, false);
</script>

This seems to solve the issue and I haven't come across any side effects.

Santiago-Czop avatar Oct 08 '24 17:10 Santiago-Czop