gpt4 book ai didi

dart - Flutter:如何在同一个类的静态方法中访问成员

转载 作者:IT王子 更新时间:2023-10-29 06:59:29 26 4
gpt4 key购买 nike

我有一个带有静态方法的类(运行计算隔离)

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)

如何从静态 decodeProfileImage 访问 tempPath 成员。 -感谢阅读。

最佳答案

编辑:

这已经改变了,回调可以是静态方法:参见https://api.flutter.dev/flutter/foundation/ComputeCallback.html .

我没有尝试过,也没有找到相关的更新日志。我希望文档是正确的。

原创

https://docs.flutter.io/flutter/foundation/compute.html

The callback argument must be a top-level function, not a closure or an instance or static method of a class.

特别注意

not a ... or static method of a class

Future doSomethingInIsolate() async {
var result = await compute(decodeProfileImage, data);
}


File decodeProfileImage(File imageFile) {
var resize = ResizeImage();
resize...
}

class ResizeImage {

ResizeImage(this.tempPath) {
...
}

}

关于dart - Flutter:如何在同一个类的静态方法中访问成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53599501/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com