gpt4 book ai didi

Flutter 分享图片 - 打开失败 : ENOENT (No such file or directory), null, null)

转载 作者:行者123 更新时间:2023-12-04 14:11:13 26 4
gpt4 key购买 nike

https://pub.dev/packages/share

Dependency: 
share: ^0.6.5+2

本地文件目录

Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}

分享功能

Future<void> _onShare(BuildContext context) async {
final RenderBox box = context.findRenderObject();
final path = await _localPath;

await Share.shareFiles(
['$path/assets/images/${widget.imgUrl}.png'],
text: text,
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
}

按钮 - 按下

FlatButton(child: Text('Share'), onPressed: () => _onShare(context)),

我正在使用这个包来分享来自应用程序的图像。我在共享文本时没有问题,但是当我添加共享图像的功能时,我不断收到丢失图像的错误。我做得对吗?

最佳答案

设法找出问题所在。看来我需要先保存图像才能引用图像。

final ByteData bytes = await rootBundle
.load('assets/images/${widget.imgUrl}.png');
final Uint8List list = bytes.buffer.asUint8List();
final directory = (await getExternalStorageDirectory()).path;
File imgFile = File('$directory/screenshot.png');
imgFile.writeAsBytesSync(list);

Share.shareFiles(['$directory/screenshot.png'],
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);

关于Flutter 分享图片 - 打开失败 : ENOENT (No such file or directory), null, null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64166203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com