deakjahn / flutter_dropzone

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

[Bug] SyntaxError: Identifier 'FlutterDropzone' has already been declared #3

Closed orestesgaolin closed 4 years ago

orestesgaolin commented 4 years ago

After adding the DropZone and pressing CMD+S following error appears:

SyntaxError: Identifier 'FlutterDropzone' has already been declared

image

Sample code:

                DropzoneView(
                  operation: DragOperation.copy,
                  onCreated: (ctrl) => controller ??= ctrl,
                  onLoaded: () => logger.d('Zone loaded'),
                  onError: (ev) => logger.d('Error: $ev'),
                  onDrop: _onDrop,
                  onHover: _onHover,
                ),

Flutter 1.19.0-5.0.pre Chrome 83.0.4103.106 on macOS

deakjahn commented 4 years ago

Apparently a kind of limitation (actually, a stricter syntax) introduced by EcmaScript 6. Basically, JavaScript now has strict rules about not allowing classes to be declared twice, which is rather normal in itself. But while Flutter hot reload certainly does some magic under the hood to work around this problem for itself, I'm not sure it's available to a plugin. Actually, right now I don't even know how they do it themselves (it's not sure they actually use ES6 anywhere, though). :-)

deakjahn commented 4 years ago

@orestesgaolin Please, check this. I'm aware of the Bad state: Future already completed error, it seems to be a recurring Flutter error, annoying but harmful, cropping up quite often on hot reload in many scenarios.

orestesgaolin commented 4 years ago

Hey, thanks for letting me know. I used the current master and indeed the previous error is gone and now I see following:

image

deakjahn commented 4 years ago

I can't seem to be able to reproduce this. Debug or release? First run or reload?

orestesgaolin commented 4 years ago
    html.window.addEventListener('flutter_dropzone_web_ready', (_) {
      if (!_readyCompleter.isCompleted) _readyCompleter.complete(true);
    });

It appears to be the same error as yours. Checking for the completer seems to solve the issue

deakjahn commented 4 years ago

Oh, the bad future state? Then it might even be fixable, after all...? :-)

orestesgaolin commented 4 years ago

The callback was called three times in my case, I don't know why. I'm not sure if that's enough to fix but this simple change gets rid of the exception

deakjahn commented 4 years ago

You must be right. I saw this error in so many places with so many different plugins that I just accepted it as a Flutter problem and never actually checked it in detail.

deakjahn commented 4 years ago

Then if it's really all right, I might just as well send it to Pub.