Flutter Image Cropper无法加载资源



在为我的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()

最新更新