1

我正在使用 Flutter 开发一个应用程序,该应用程序获取图像并允许用户将其保存在图库中。

我正在使用image_picker_saver插件来保存它。

一开始我在调用将图像保存在主线程中的方法,但我意识到这真的很慢,现在我试图把它放在一个新的隔离线程中,但我总是遇到同样的错误,所以,我的问题是:如何调用该方法将图像保存在新的隔离线程中?

我的代码如下所示:

主要.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 线程中使用。

找不到“Window_sendPlatformMessage”(4 个参数)

4

2 回答 2

2

我把问题放在 GitHub 上,基本上插件只能在主 UI 线程中使用。

找不到“Window_sendPlatformMessage”(4 个参数)

于 2019-01-28T12:17:35.120 回答
1

您可以尝试使用https://pub.dev/packages/flutter_isolate生成一个支持 Flutter 插件的隔离。

于 2019-05-14T23:41:06.127 回答