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

Error when user tries to drop text #68

Closed crizant-mpower closed 11 months ago

crizant-mpower commented 11 months ago

Select some text on the address bar, then drag it over the dropzone, the following error is thrown:

Error: Expected a value of type
'File$', but got one of type 'String'
../dart-sdk/lib/_internal/js_dev_runtim
e/private/ddc_runtime/errors.dart
288:49      throw_
../dart-sdk/lib/_internal/js_dev_runtim
e/private/ddc_runtime/errors.dart 121:3
castError
deakjahn commented 11 months ago

@crizant-mpower Yep but I'm not yet sure what the best solution would be. onDrop() has a File as second argument. We could change it to dynamic (just like onDropMultiple()) but that would be a breaking change of the interface. We could also add a different onDrop() variant but I can't really see why.

deakjahn commented 11 months ago

Wait a minute... The handler itself is OK, it was an intermediate function somewhere with the File argument...

Check out the changes, please.

crizant-mpower commented 11 months ago

Thanks. I'm fine with the changes. Looking forward to the next release.

deakjahn commented 11 months ago

Published now.

crizant-mpower commented 11 months ago

Sorry, it seems you forgot to update the onDropMultiple method. When I drop text, the onDropMultiple method is not invoked.

deakjahn commented 11 months ago

Oh, dear me, that'll be an async problem with JavaScript...

deakjahn commented 11 months ago

@crizant-mpower OK, this is definitively something I don't want to publish before you test it. :-) See https://github.com/deakjahn/flutter_dropzone/commit/72300858eb32c865fbf7b2f10624dda5a82791a1

Basically, getting the string is async so we actually went on to fire (or not fire) onDropMultiple before the string got a chance to be set (files are not problematic because, for some obscure reason, getting them is sync). I added a private helper function to make getting the string synchronous. The change is straightforward and seems to work for my simple tests but let's be sure first...

crizant-mpower commented 11 months ago

@crizant-mpower OK, this is definitively something I don't want to publish before you test it. :-) See 7230085

Basically, getting the string is async so we actually went on to fire (or not fire) onDropMultiple before the string got a chance to be set (files are not problematic because, for some obscure reason, getting them is sync). I added a private helper function to make getting the string synchronous. The change is straightforward and seems to work for my simple tests but let's be sure first...

I tested and it works like a charm. 🎉

deakjahn commented 11 months ago

Then it's released again, thanks.