proversion
proversion

Reputation: 593

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';
   }

Upvotes: 8

Views: 14041

Answers (1)

nonybrighto
nonybrighto

Reputation: 9593

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.'); 

Upvotes: 10

Related Questions