whatsapp_sender_flutter 0.0.1 whatsapp_sender_flutter: ^0.0.1 copied to clipboard
WhatsApp Sender is an unofficial API for Flutter to send bulk messages in Whatsapp
WhatsApp Sender #
WhatsApp Sender 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.
Getting Started #
In the pubspec.yaml
of your flutter project, add the following dependency:
dependencies:
...
whatsapp_sender_flutter: ^0.0.1
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.
Problem If the automatic download doesn't work you can copy the folder, which you can download from here, manually in your project root.
Basic usage #
The process for sending messages is like for WhatsApp Web:
- Scan the qr code
- 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';
...
ValueListenableBuilder<String>(
valueListenable: WhatsAppSender.qrCode,
builder: (context, value, widget) {
return value.isEmpty
? const SizedBox()
: PrettyQr(
size: 300,
data: value,
roundEdges: true,
);
},
),
The static variable WhatsAppSender.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!
await WhatsAppSender.sendTo(
phones: [ "+391111111", "+391111111", "+391111111"],
message: "Hello",
);
Advanced usage #
Listen sending status #
ValueListenableBuilder<String>(
valueListenable: WhatsAppSender.status,
builder: (context, value, widget) {
return Text(value);
},
),
The static variable WhatsAppSender.status
is a ValueNotifier
. You can use ValueListenableBuilder
to listen changes.
Possible states of WhatsAppSender.status
are:
WhatsAppSenderStatusMessage.initialize
during WhatsApp initializationWhatsAppSenderStatusMessage.scanQrCode
during qr code scanningWhatsAppSenderStatusMessage.sending
during sendingWhatsAppSenderStatusMessage.done
if seding is endWhatsAppSenderStatusMessage.qrCodeExpirated
if qrcode to scan is expirated
Listen the number of success sendings #
ValueListenableBuilder<String>(
valueListenable: WhatsAppSender.success,
builder: (context, value, widget) {
return Text(value.toString());
},
),
The static variable WhatsAppSender.success
is a ValueNotifier
. You can use ValueListenableBuilder
to listen changes.
Listen the number of fails sendings #
ValueListenableBuilder<String>(
valueListenable: WhatsAppSender.fails,
builder: (context, value, widget) {
return Text(value.toString());
},
),
The static variable WhatsAppSender.fails
is a ValueNotifier
. You can use ValueListenableBuilder
to listen changes.
Save your session #
await WhatsAppSender.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> {
@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: WhatsAppSender.qrCode,
builder: (context, value, widget) {
return value.isEmpty
? const SizedBox()
: PrettyQr(
size: 300,
data: value,
roundEdges: true,
);
},
),
ValueListenableBuilder<String>(
valueListenable: WhatsAppSender.status,
builder: (context, value, widget) {
return Text(value);
},
),
ValueListenableBuilder<int>(
valueListenable: WhatsAppSender.success,
builder: (context, value, widget) {
return Text("$value success");
},
),
ValueListenableBuilder<int>(
valueListenable: WhatsAppSender.fails,
builder: (context, value, widget) {
return Text("$value fails");
},
),
],
),
),
),
);
await WhatsAppSender.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!)