deakjahn / flutter_dropzone

A drag-and-drop Flutter plugin (Web). Only web and only from outside into Flutter.
https://pub.dev/packages/flutter_dropzone
85 stars 36 forks source link

onError or onLeave not called when incorrect mime type dropped #66

Closed gbmiranda closed 11 months ago

gbmiranda commented 12 months ago

Hi,

onLeave or onError is not being called after dropping a file not allowed by the mime type.

Any chance of correction?

deakjahn commented 12 months ago

I'm not really sure this would be a good idea, it was never intended that way. MIME types simply restrict the droppable files but don't necessarily mean a hard error. It would certainly be a breaking change if we modified that behavior now...

gbmiranda commented 12 months ago

Hi, thanks for the quick response! Your arguments are valid, but we have some situations:

1- the onHover is called for files not accepted and I highlight the zone, if the user tries to add I have no event afterwards to remove the highlight and give a feedback warning that files are not accepted, maybe create a new event called onDropInvalid ? 2- another UX suggestion, when I place the file above the zone, the cursor shows a green icon, when for an invalid file, it displays a red icon.

I even managed to solve the hover issue by adding a MouseRegion over the zone and controlling it by onEnter / onExite, but I still haven't seen a way to display feedback to the user warning that the file is not accepted.

deakjahn commented 12 months ago

@gbmiranda Adding a new callback wasn't that complicated. Please, check it out.

gbmiranda commented 12 months ago

Perfect thank you! Will you publish to pub.dev?

deakjahn commented 12 months ago

If you say it's safe to do so...

gbmiranda commented 12 months ago

onDropInvalid event was not called :(

deakjahn commented 12 months ago

I tried the example, even left the MIME there for now and it works for me. Did you try that directly?

gbmiranda commented 12 months ago

I tried it on my own project, here's a print of the code.

mime: ['image/jpeg', 'image/jpg', 'image/png'];

Captura de Tela 2023-07-28 às 08 24 30

When I drop a CSV or ZIP file, the onDropInvalid event does not fire

deakjahn commented 12 months ago

Then first, please, try the example, that's the one we have in common...

gbmiranda commented 11 months ago

if I download the example and run it, it works, but when I put it in my project with version 3.0.6 it doesn't. Even if I exactly copy your DropZone implementation the onDropInvalid event is not called.

Could it be that something was missing from the uploaded version?

deakjahn commented 11 months ago

Strange. All three seem to be upgraded:

Do check in your Pub\Cache\hosted\pub.dev that you have these versions of all three.

I'll try to reproduce it in a standalone test in the meantime.

deakjahn commented 11 months ago

@gbmiranda I really can't get a handle on this yet. I started a new project, web only. I copied main.dart from the plugin example. Here it is packed, I modified nothing else from the standard Flutter project template: untitled.zip but it references the current version from Pub.dev.

And it runs just fine:

Untitled-1

deakjahn commented 11 months ago

What you could do is to put a breakpoint here in your browser Dev Tools and see what really happens, step by step:

https://github.com/deakjahn/flutter_dropzone/blob/be7275b4d92c1fdb3e3c4e60a57518dba32d17fa/flutter_dropzone_web/lib/assets/flutter_dropzone.js#L52-L59

gbmiranda commented 11 months ago

I'm thinking it's a flutter package caching problem... the file you sent me doesn't have the onDropInvalid handlers

Captura de Tela 2023-07-31 às 10 06 27
gbmiranda commented 11 months ago

For some reason I need to override flutter_dropzone_web to get the right version.

Working now!

Captura de Tela 2023-07-31 às 10 35 10
deakjahn commented 11 months ago

I didn't yet change it to .10 in the .yaml, that's true, but it should work, anyway, this is rather strange. What if you delete all the version folders in the pub cache and run pub get again? Do you get version .10 then?

gbmiranda commented 11 months ago

takes 3.0.9 and 3.0.10, but for some reason when I build it uses 3.0.9... it only works if I override it.

deakjahn commented 11 months ago

Who knows. I advanced the version now here and it will appear in the next published one.