【发布时间】:2020-03-11 06:10:33
【问题描述】:
我使用 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());
}
}
当我尝试使用上述函数分享我生成的图像时,发生异常,
我应该怎么做才能解决这个问题。我认为这会因为通道参数而发生。
【问题讨论】:
-
MissingPluginException 通常是因为您更改了 .yaml 文件,然后使用了新添加的插件,但您没有重新启动(不是热重载)您的应用程序。确保重新启动调试会话,它应该可以工作。
-
我也重新启动了调试会话,但它不起作用。
标签: image flutter dart share flutter-plugin