我有一个带有静态方法的类(用于运行计算隔离)
class ResizeImage {
ResizeImage(this.tempPath) {
sTempPath = tempPath;
print('main()resizeMyProImage.dart...IN CLASS.........imgFile tempPath: '+tempPath);
print('main()resizeMyProImage.dart...IN CLASS.........imgFile sTempPath: '+sTempPath);
}
String tempPath;
static String sTempPath
....
static File decodeProfileImage(File imageFile) {
// get sTempPath here...
print('decodeProfileImage...decodeImage.dart...IN CLASS.......well.tempPath......hit with: '+sTempPath);
// Im.Image image = Im.decodeImage(imageFile.readAsBytesSync());
// Im.Image smallerImage = Im.copyResize(image, 150); // choose the size here, it will maintain aspect ratio
// return new File(sTempPath+'thumbnail.jpg')
// ..writeAsBytesSync(Im.encodeJpg(smallerImage, quality: 85));
}
我正在另一堂课中实例化……
ResizeImage resizeImage = new ResizeImage(tempPath);
print('uploadFile >>>>>>>>>>>>>>>>>>>>>....hit begin 000 resizeImage.tempPath: '+resizeImage.tempPath);
File myFile;
if (isProfilePic) myFile = (await resizeImage.resizeMyProImage(file));
错误:
Isolate (389190561) 'main.dart:_spawn()' exited with an error
E/flutter ( 2369): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 2369): Invalid argument(s)
E/flutter ( 2369): #0 _StringBase.+ (dart:core/runtime/libstring_patch.dart:246:57)
如何从静态的解码配置文件图像访问tempPath成员。 -感谢阅读。
答案 0 :(得分:1)
https://docs.flutter.io/flutter/foundation/compute.html
回调参数必须是顶级函数,而不是类的闭包,实例或静态方法。
特别注意
不是类的...或静态方法
Future doSomethingInIsolate() async {
var result = await compute(decodeProfileImage, data);
}
File decodeProfileImage(File imageFile) {
var resize = ResizeImage();
resize...
}
class ResizeImage {
ResizeImage(this.tempPath) {
...
}
}