[英]Flutter Image Cropper unable to load asset
After using the image_cropper plugin for my Flutter app, I get this error:为我的 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>
This is my code to crop the image:这是我裁剪图像的代码:
_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;
});
}
}
I visualise the image with AssetImage(_image.path).我使用 AssetImage(_image.path) 可视化图像。
This error only occurs after I started the emulator.此错误仅在我启动模拟器后发生。 As soon as I make one hot reload, I can see the image, it displays correctly, and I never get this error again.
一旦我进行一次热重载,我就可以看到图像,它显示正确,而且我再也不会出现此错误。 But as soon as I restart the emulator, the error occurs again.
但是一旦我重新启动模拟器,错误就会再次发生。 I also tested it on a real device and the error occurs constantly.
我还在真实设备上对其进行了测试,错误不断发生。
Any idea what the problem could be?知道可能是什么问题吗?
Had the same problem.有同样的问题。
My fix:我的修复:
OLD老的
final ByteData bytes = await rootBundle.load(filePath);
NEW新的
final ByteData bytes= file.readAsBytesSync().buffer.asByteData()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.