1

I wrapped exif-js library via dart:js.

  @JS()
    library exif;

    import 'package:js/js.dart';

    @JS()
    external PhotoDetails get EXIF;

    @JS()
    class PhotoDetails {
      factory PhotoDetails() {
        return EXIF;
      }

      @JS()
      external bool getData(img, callback);
}

And have a little Dart program:

PhotoDetails photoDetails = new PhotoDetails();
    var fileUploadInputElement = new FileUploadInputElement();
    fileUploadInputElement.onChange.listen((e) => photoDetails.getData(
        fileUploadInputElement.files[0], () {
      print(this);
    }));

Here it was already answered, but when I made so, I have this js error: exif.js:351 Uncaught TypeError: callback.call is not a function I tried to cast manually to Function. But it has not helped. With lambda expression it was the same.

1 Answer 1

1

I think you need allowInterop or allowInteropCaptureThis

PhotoDetails photoDetails = new PhotoDetails();
var fileUploadInputElement = new FileUploadInputElement();
fileUploadInputElement.onChange.listen((e) => photoDetails.getData(
    fileUploadInputElement.files[0], allowInteropCaptureThis((self, [_]) {
  print(self);
})));
Sign up to request clarification or add additional context in comments.

6 Comments

I am not sure, that your answer is reason, but now it throws Uncaught Unhandled exception: Closure call with mismatched arguments: function 'call' NoSuchMethodError: incorrect number of arguments passed to method named 'call' Receiver: Closure: () => dynamic Tried calling: call(Instance of 'FileImpl') Found: call() #0 Object._noSuchMethod (dart:core-patch/object_patch.dart:42) #1 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
I updated my answer (added [_, __]). Can you please try if this has any effect (different error, ...)?
This not crashing, but for a pity print a "". So now I need to go deeper and find my mistake. Thanks a lot.
Try print(_); instead of print(this). _ and __ are just names for unused variables. You can use proper names for them instead. [...] is to make them optional because I didn't know how many parameters are tried to pass and just used two of them. I assume the first is this (not sure, it's a while I tried this myself)
Yes, this works. Very big thanks! Can you edit your answer?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.