【问题标题】:Cant find image by path in Flutter无法在 Flutter 中按路径查找图像
【发布时间】:2021-09-07 13:02:42
【问题描述】:

无法共享知道其路径的图像。我用“images/image.png”调用这个函数并得到: 未处理的异常:PlatformException(images/baws.png: open failed: ENOENT (No such file or directory), null, null, null)

shareImage(BuildContext context, String imagePath) async {
    final ByteData bytes = await rootBundle.load(imagePath);
    await Share.file('Essi', imagePath, bytes.buffer.asUint8List(), 'images/png');
}

有人知道如何解决这个问题吗?

【问题讨论】:

  • 图片路径来自哪里?
  • 我根据用户单击的图像更改变量。它具有“图像/图像”的格式,并且可以与图像小部件一起正常工作。
  • 图片来自资产还是设备?
  • 来自资产
  • 这不可能

标签: image flutter file path


【解决方案1】:

您必须将图像目录添加到您的 pubspec.yaml

assets:
    # path to image dir
    - assets/images/ 

确保你做了flutter pub get

如果您已经这样做了,请尝试重新启动您的应用。

如果没有成功,我们将需要更多信息才能进行调试

【讨论】:

  • 我做到了。如果我想使用 image1,我可以使用 images/image1 作为路径,但如果我想将它与共享插件一起使用,它会告诉我找不到文件。
猜你喜欢
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-25
  • 1970-01-01
  • 2020-01-07
  • 2017-05-22
相关资源
最近更新 更多