Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share image to whatsapp from flutter application?

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';
   }
like image 203
proversion Avatar asked Jun 14 '19 03:06

proversion


1 Answers

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.'); 
like image 140
nonybrighto Avatar answered Nov 15 '22 08:11

nonybrighto