我正在使用Flutter开发一个应用程序,该应用程序可以拍摄图像并允许用户将其保存在图库中。
我正在使用image_picker_saver插件进行保存。
在一开始,我就调用了将图像保存在主线程中的方法,但是我意识到这确实很慢,现在我试图将其放在一个新的隔离线程中,但是我一直都遇到相同的错误,因此,我的问题是:如何调用将图像保存到新的隔离线程中的方法?
我的代码如下:
Main.dart
class _AkkaMark extends State<CameraUpload>{
.
.
.
void _clickSaveImage() {
compute(saveImage, _imageFile).then((Future<String> futurePath) {
futurePath.then((String path){
_imageFile = new File(path);
});
});
}
.
.
.
}
toCompute.dart
Future<String> saveImage(File image) async {
return await ImagePickerSaver.saveFile(fileData: image.readAsBytesSync());
}
我试图更改代码以查找错误,但始终相同:
E/flutter (22602): [ERROR:flutter/runtime/dart_isolate.cc(717)] Isolate (413787440) 'main.dart:_spawn()' exited with an error
E/flutter (22602): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (22602): error: native function 'Window_sendPlatformMessage' (4 arguments) cannot be found
E/flutter (22602): #0 Window.sendPlatformMessage (dart:ui/window.dart:811:9)
E/flutter (22602): #1 BinaryMessages._sendPlatformMessage (package:flutter/src/services/platform_messages.dart:40:15)
E/flutter (22602): #2 BinaryMessages.send (package:flutter/src/services/platform_messages.dart:88:12)
E/flutter (22602): #3 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:286:49)
E/flutter (22602): <asynchronous suspension>
E/flutter (22602): #4 ImagePickerSaver.saveFile (package:image_picker_saver/image_picker_saver.dart:77:38)
E/flutter (22602): <asynchronous suspension>
E/flutter (22602): #5 saveImage (package:AKKAmark/toCompute.dart:113:35)
E/flutter (22602): <asynchronous suspension>
E/flutter (22602): #6 _IsolateConfiguration.apply (package:flutter/src/foundation/isolates.dart:88:16)
E/flutter (22602): #7 _spawn.<anonymous closure> (package:flutter/src/foundation/isolates.dart:96:30)
E/flutter (22602): #8 Timeline.timeSync (dart:developer/timeline.dart:168:22)
E/flutter (22602): #9 _spawn (package:flutter/src/foundation/isolates.dart:93:12)
E/flutter (22602): #10 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:292:17)
E/flutter (22602): #11 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
有人有什么线索吗?预先感谢
我在GitHub上提出了这个问题,基本上插件只能在主UI线程中使用。
答案 0 :(得分:0)
我在GitHub上提出了这个问题,基本上插件只能在主UI线程中使用。
答案 1 :(得分:0)
您可以尝试使用https://pub.dev/packages/flutter_isolate生成支持Flutter插件的隔离。