【问题标题】:Flutter Image Cropper unable to load assetFlutter Image Cropper 无法加载资源
【发布时间】:2021-03-05 13:39:14
【问题描述】:

在我的 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) 可视化图像。

此错误仅在我启动模拟器后发生。一旦我进行一次热重载,我就可以看到图像,它显示正确,并且我再也不会收到此错误。但是一旦我重新启动模拟器,错误就会再次发生。 我也在真机上测试过,一直报错。

知道可能是什么问题吗?

【问题讨论】:

    标签: flutter cropper


    【解决方案1】:

    遇到同样的问题。

    我的解决方法:

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

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

    【讨论】:

    • 您在哪里进行了更改?
    猜你喜欢
    • 2021-06-05
    • 2019-05-23
    • 2020-04-28
    • 2021-05-10
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    相关资源
    最近更新 更多