问题
I am developing an app with Flutter that takes an image and allows the user to save it in the gallery.
I am using image_picker_saver plugin to save it.
In the beginning I was calling the method to save the image in the main thread but I realized that was really slow and now I am trying to put it in a new isolated thread, but I am getting the same error all the time, so, my question is: How can I call the method to save the image in a new isolated thread?
My code looks like this:
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());
}
I tried to change the code trying to locate the error but is always the same:
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)
Someone has any clue? Thanks in advance
Edit
I put the question on GitHub and basically plugins only can be used in the main UI thread.
'Window_sendPlatformMessage' (4 arguments) cannot be found
回答1:
I put the question on GitHub and basically plugins only can be used in the main UI thread.
'Window_sendPlatformMessage' (4 arguments) cannot be found
回答2:
You can try using https://pub.dev/packages/flutter_isolate to spawn an isolate that supports Flutter plugins.
来源:https://stackoverflow.com/questions/54127158/flutter-window-sendplatformmessage-4-arguments-cannot-be-found