image - 无法使用 Flutter 通道共享文件 - 缺少插件异常
问题描述
我使用flutter-darts创建了QR 码生成应用程序。一切都很好,除了分享部分。我使用以下代码来分享我生成的png 图像。
Future<Null> _captureAndSharePng() async {
try {
RenderRepaintBoundary boundary =
globalKey.currentContext.findRenderObject();
var image = await boundary.toImage();
ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
final tempDir = await getTemporaryDirectory();
final file = await new File('${tempDir.path}/image.png').create();
await file.writeAsBytes(pngBytes);
/*final channel = const MethodChannel('channel:me.alfian.share/share');
assert(image != null);
return channel.invokeMethod('shareImage', image);*/
final channel = const MethodChannel('channel:me.alfian.share/share');
channel.invokeMethod('shareFile', 'image.png');
} catch (e) {
print(e.toString());
}
}
当我尝试使用上述功能共享我生成的图像时,发生异常,
我应该怎么做才能解决这个问题。我认为这会因为通道参数而发生。
解决方案
我做过类似的事情,发现插件 esys_flutter_share:
带来了调用跨平台共享的最佳方法。
试试这个代码片段,这对我有用:
await Share.file(
'Export', 'export.png', file.readAsBytesSync(), 'export/png');
推荐阅读
- javascript - 转换后的功能组件(具有角色权限的切换按钮)停止工作
- java - 如何在 Firebase 存储中上传位图屏幕截图并获取其下载 URL?(了解已弃用的 getDownloadURL())
- eclipse - Tomcat 应用程序使用完整的路径和资源,否则不能
- delphi - 如何从注册表 HKEY_LOCAL_MACHINE 中读取?
- oracle - 为什么 oracle 选择 INDEX FULL SCAN 然后选择 ACCESS BY INDEX ROWID vs FULL TABLE SCAN?
- java - JSON解析字符串失败,但Java中的数字通过
- node.js - 如何在节点中的 2 个嵌套循环后执行代码
- swift - 在 Swift 中计算方程
- python - 通过python将随机数据插入到具有MySQL数据库外键的表中
- python - Socks5 代理引发“连接意外关闭”和“[Errno 104] 对等连接重置”