对包装的 js 使用 dart 回调
Use dart callback for wrapped js
我通过 dart:js
.
包装了 exif-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);
}
还有一点 Dart 程序:
PhotoDetails photoDetails = new PhotoDetails();
var fileUploadInputElement = new FileUploadInputElement();
fileUploadInputElement.onChange.listen((e) => photoDetails.getData(
fileUploadInputElement.files[0], () {
print(this);
}));
Here 已经有人回答了,但是当我这样做的时候,我有这个 js 错误:exif.js:351 Uncaught TypeError: callback.call is not a function
我试图手动转换为函数。但它没有帮助。对于 lambda 表达式,它是一样的。
我认为你需要 allowInterop
或 allowInteropCaptureThis
PhotoDetails photoDetails = new PhotoDetails();
var fileUploadInputElement = new FileUploadInputElement();
fileUploadInputElement.onChange.listen((e) => photoDetails.getData(
fileUploadInputElement.files[0], allowInteropCaptureThis((self, [_]) {
print(self);
})));
我通过 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);
}
还有一点 Dart 程序:
PhotoDetails photoDetails = new PhotoDetails();
var fileUploadInputElement = new FileUploadInputElement();
fileUploadInputElement.onChange.listen((e) => photoDetails.getData(
fileUploadInputElement.files[0], () {
print(this);
}));
Here 已经有人回答了,但是当我这样做的时候,我有这个 js 错误:exif.js:351 Uncaught TypeError: callback.call is not a function
我试图手动转换为函数。但它没有帮助。对于 lambda 表达式,它是一样的。
我认为你需要 allowInterop
或 allowInteropCaptureThis
PhotoDetails photoDetails = new PhotoDetails();
var fileUploadInputElement = new FileUploadInputElement();
fileUploadInputElement.onChange.listen((e) => photoDetails.getData(
fileUploadInputElement.files[0], allowInteropCaptureThis((self, [_]) {
print(self);
})));