whatsapp_sender_flutter 0.0.9 copy "whatsapp_sender_flutter: ^0.0.9" to clipboard
whatsapp_sender_flutter: ^0.0.9 copied to clipboard

outdated

WhatsApp Sender Flutter is an unofficial API for Flutter to send bulk messages in Whatsapp

WhatsApp Sender Flutter #

WhatsApp Sender Flutter is an unofficial API for Flutter to send bulk messages in Whatsapp. It's not recommended using it in your company or for marketing purpose.

Buy Me A Book

Getting Started #

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  whatsapp_sender_flutter: latest

Import it:

import 'package:whatsapp_sender_flutter/whatsapp_sender_flutter.dart';

Configuration #

For the first usage, wait for the automatic download of the .local-chromium folder in your project root. Without this folder the package will not work,this is because this package is based on puppeteer.

If automatic download doent't start

  1. Download .zip file
  • Mac download from here
  • Windows download from here
  • Linux download from here
  1. Extract .zip file and move content in the .local-chromium (create it if it doesn't exist ) folder manually in your project root.

Basic usage #

The process for sending messages is like for WhatsApp Web:

  1. Scan the qr code
  2. Start the sending

Render qrcode to scan #

For render qrcode to scan use package like pretty_qr_code.

   import 'package:pretty_qr_code/pretty_qr_code.dart';
   WhatsAppSenderFlutter whatsAppSenderFlutter = WhatsAppSenderFlutter();
   ...
   ValueListenableBuilder<String>(
     valueListenable: whatsAppSenderFlutter.qrCode,
     builder: (context, value, widget) {
              return value.isEmpty 
                     ? const SizedBox()
                      : PrettyQr(
                          size: 300,
                          data: value,
                          roundEdges: true,
                        );
                      },
  ),

The static variable whatsAppSenderFlutter.qrCode is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Start the sending #

After you have scanned the code, you can start the sending campaign.

All phones must contain the international prefix!

   WhatsAppSenderFlutter whatsAppSenderFlutter = WhatsAppSenderFlutter();
   ...
   await whatsAppSenderFlutter.sendTo(
         phones: [ "+391111111", "+391111111", "+391111111"],
         message: "Hello",
   );

Advanced usage #

Listen sending status #

   WhatsAppSenderFlutter whatsAppSenderFlutter = WhatsAppSenderFlutter();
   ...
   ValueListenableBuilder<String>(
     valueListenable: whatsAppSenderFlutter.status,
     builder: (context, value, widget) {
                return Text(value);
              },
  ),

The static variable whatsAppSenderFlutter.status is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Possible states of WhatsAppSenderFlutter.status are:

  • WhatsAppSenderFlutterStatusMessage.initialize during WhatsApp initialization
  • WhatsAppSenderFlutterStatusMessage.scanQrCode during qr code scanning
  • WhatsAppSenderFlutterStatusMessage.sending during sending
  • WhatsAppSenderFlutterStatusMessage.done if seding is end
  • WhatsAppSenderFlutterStatusMessage.qrCodeExpirated if qrcode to scan is expirated

Listen the number of success sendings #

   WhatsAppSenderFlutter whatsAppSenderFlutter = WhatsAppSenderFlutter();
   ...
   ValueListenableBuilder<String>(
     valueListenable: whatsAppSenderFlutter.success,
     builder: (context, value, widget) {
                return Text(value.toString());
              },
  ),

The static variable whatsAppSenderFlutter.success is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Listen the number of fails sendings #

   WhatsAppSenderFlutter whatsAppSenderFlutter = WhatsAppSenderFlutter();
   ...
   ValueListenableBuilder<String>(
     valueListenable: whatsAppSenderFlutter.fails,
     builder: (context, value, widget) {
                return Text(value.toString());
              },
  ),

The static variable whatsAppSenderFlutter.fails is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Save your session #

   WhatsAppSenderFlutter whatsAppSenderFlutter = WhatsAppSenderFlutter();
   ...
   await whatsAppSenderFlutter.sendTo(
         phones: [ "+391111111", "+391111111", "+391111111"],
         message: "Hello",
         savedSessionDir: "./userData"
   );

To save the session you must indicate a folder name in savedSessionDir.

If you save the session you will no longer have to scan the qr code !

Do not indicate savedSessionDir if you want to be asked to scan the qr code at each sending.

Example #

import 'package:flutter/material.dart';
import 'package:pretty_qr_code/pretty_qr_code.dart';
import 'package:whatsapp_sender/whatsapp_sender.dart';

void main() {
  runApp(
    const MaterialApp(
      home: MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  WhatsAppSenderFlutter whatsAppSenderFlutter = WhatsAppSenderFlutter();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.send),
        onPressed: () async {
          showDialog(
            context: context,
            builder: (context) => AlertDialog(
              content: SingleChildScrollView(
                child: Column(
                  children: [
                    ValueListenableBuilder<String>(
                      valueListenable: whatsAppSenderFlutter.qrCode,
                      builder: (context, value, widget) {
                        return value.isEmpty
                            ? const SizedBox()
                            : PrettyQr(
                                size: 300,
                                data: value,
                                roundEdges: true,
                              );
                      },
                    ),
                    ValueListenableBuilder<String>(
                      valueListenable: whatsAppSenderFlutter.status,
                      builder: (context, value, widget) {
                        return Text(value);
                      },
                    ),
                    ValueListenableBuilder<int>(
                      valueListenable: whatsAppSenderFlutter.success,
                      builder: (context, value, widget) {
                        return Text("$value success");
                      },
                    ),
                    ValueListenableBuilder<int>(
                      valueListenable: whatsAppSenderFlutter.fails,
                      builder: (context, value, widget) {
                        return Text("$value fails");
                      },
                    ),
                  ],
                ),
              ),
            ),
          );
          await whatsAppSenderFlutter.sendTo(
            phones: [
              "+391111111111",
              "+391111111111",
              "+391111111111",
            ],
            message: "Hello",
          );
        },
      ),
      appBar: AppBar(
        title: const Text("WhatsApp sender"),
      ),
      body: const Center(
        child: Text("Press send button to start the sending"),
      ),
    );
  }
}

To Do #

  • Send text message ✔️
  • Send image (coming soon!)

License #

MIT

30
likes
0
pub points
76%
popularity

Publisher

unverified uploader

WhatsApp Sender Flutter is an unofficial API for Flutter to send bulk messages in Whatsapp

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, puppeteer

More

Packages that depend on whatsapp_sender_flutter