whatsapp_share2 2.0.2 copy "whatsapp_share2: ^2.0.2" to clipboard
whatsapp_share2: ^2.0.2 copied to clipboard

Simple way to share message, links or files from your flutter app to specific contact in whatsapp

Whatsapp Share Plugin #

A Flutter plugin for IOS and Android providing a simple way to share a message, link or local files to specific WhatsApp contact.

Features: #

  • null safe
  • Share messages or link urls to specific contact.
  • Share local files to specific contact.

Installation #

First, add this to your package's pubspec.yaml file:

dependencies:
  whatsapp_share2: ^2.0.0
copied to clipboard

Now in your Dart code, you can use:

import 'package:whatsapp_share2/whatsapp_share2.dart';
copied to clipboard

Installation (Platform Specific) #

iOS #

Add if not exists one row to the ios/podfile after target runner:

...

target 'Runner' do
    use_frameworks!

...
copied to clipboard

Android #

If you pretends to use the file share, you need to configure the file provider, this will give access to the files turning possible to share with other applications.

Add to AndroidManifest.xml:

<application>
...
<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths"/>
</provider>
</application>
copied to clipboard

Obs: You can change the android:name if you have an extension of file provider.

Add res/xml/provider_paths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>
copied to clipboard

If you want to learn more about file provider you can access:

How to use? #

Here is an snippets app displaying the two whatsapp share methods .

Whatsapp installed in this device ? #

 Future<void> isInstalled() async {
    final val = await WhatsappShare.isInstalled(
      package: Package.businessWhatsapp
    );
    print('Whatsapp Business is installed: $val');
  }
copied to clipboard

If whatsapp is not installed, please do not call WhatsappShare.share() and WhatsappShare.shareFile()


 Future<void> share() async {
    await WhatsappShare.share(
      text: 'Whatsapp share text',
      linkUrl: 'https://flutter.dev/',
      phone: '91xxxxxxxxxx',
    );
  }

copied to clipboard

Share images, files #

_image1.path contains path of the file which is shared to the whatsapp.


 Future<void> shareFile() async {
    await WhatsappShare.shareFile(
      text: 'Whatsapp share text',
      phone: '91xxxxxxxxxx',
      filePath: [_image1.path, _image2.path],
    );
  }

```"# whatsapp_share" 
"# whatsapp_share" 
"# whatsapp_share" 
"# whatsapp_share2" 
"# whatsapp_share null safe" 
copied to clipboard
41
likes
160
points
268
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.14 - 2025.03.29

Simple way to share message, links or files from your flutter app to specific contact in whatsapp

Homepage
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on whatsapp_share2