繁体   English   中英

Flutter Image Cropper 无法加载资源

[英]Flutter Image Cropper unable to load asset

为我的 Flutter 应用程序使用 image_cropper 插件后,出现此错误:

Unable to load asset: /data/user/0/com.habbyt.version1/cache/image_cropper_1606070878133.jpg
When the exception was thrown, this was the stack
#0      PlatformAssetBundle.load
<asynchronous suspension>

这是我裁剪图像的代码:

  _cropImage(filePath) async {
    File croppedImage = await ImageCropper.cropImage(
      sourcePath: filePath,
      aspectRatio: CropAspectRatio(ratioX: 1, ratioY: 1),
      maxWidth: 1080,
      maxHeight: 1080,
    );
    if (croppedImage != null) {
      setState(() {
        _image = croppedImage;
        imageExists = true;
      });
    }
  }

我使用 AssetImage(_image.path) 可视化图像。

此错误仅在我启动模拟器后发生。 一旦我进行一次热重载,我就可以看到图像,它显示正确,而且我再也不会出现此错误。 但是一旦我重新启动模拟器,错误就会再次发生。 我还在真实设备上对其进行了测试,错误不断发生。

知道可能是什么问题吗?

有同样的问题。

我的修复:

老的

final ByteData bytes = await rootBundle.load(filePath);

新的

final ByteData bytes= file.readAsBytesSync().buffer.asByteData()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM