launchWhatsApp static method

dynamic launchWhatsApp(
  1. String whatsAppNumber, {
  2. String message = "Hello",
  3. LaunchMode mode = LaunchMode.platformDefault,
  4. String? url,
})

Launch WhatsApp with the given telephoneNumber and message. message is optional. mode is optional. url is optional, if not provided, it will use the whatsappNumber otherwise it will use the url.

Implementation

static launchWhatsApp(
  String whatsAppNumber, {
  String message = "Hello",
  LaunchMode mode = LaunchMode.platformDefault,
  String? url,
}) async {
  final String whatsAppUrl =
      "https://wa.me/$whatsAppNumber&text=${Uri.encodeFull(message)}";
  try {
    await canLaunchUrlString(url ?? whatsAppUrl)
        ? await launchUrlString(
            url ?? whatsAppUrl,
            mode: mode,
          )
        : showErrorNotice("Error", 'WhatsApp can\'t launch.');
  } catch (e) {
    logger.e(e.toString());
  }
}