How to share image to whatsapp from flutter application?

佐手、 提交于 2020-07-09 09:52:04

问题


I have to send an image from my flutter application to whatsapp directly. After launching the whatsapp, I want to select the contacts to share the image. How this possible in flutter?

I tried using url_launcher, but it is launching the specified contact. And I couldn't find the sharing option anywhere.

  const url = 'whatsapp://send?phone=$phone';
   if (await URLLauncher.canLaunch(url)) {
     await URLLauncher.launch(url);
   } 
   else {
     throw 'Could not launch $url';
   }

回答1:


You can make use of esys_flutter_share to share files in flutter. You just need to send a file as bytes and share to any external application you want.

final ByteData bytes = await rootBundle.load('assets/image1.png');
await Share.file('esys image', 'esys.png', bytes.buffer.asUint8List(), 'image/png', text: 'My optional text.'); 



回答2:


esys_flutter_share works perfectly!



来源:https://stackoverflow.com/questions/56590914/how-to-share-image-to-whatsapp-from-flutter-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!