Leonid Lunin Leonid Lunin - 5 months ago 33
Javascript Question

Use dart callback for wrapped js

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.

Answer

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);
})));
Comments