简体   繁体   中英

Flutter Image Cropper unable to load asset

After using the image_cropper plugin for my Flutter app, I get this error:

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).

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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