whatsApp static method

Future<bool> whatsApp({
  1. String? whatsAppNumber,
  2. String text = "",
  3. OpenMode mode = OpenMode.externalNonBrowserApplication,
})

share content to whatsapp

Implementation

static Future<bool> whatsApp(
    {String? whatsAppNumber,
    String text = "",
    OpenMode mode = OpenMode.externalNonBrowserApplication}) async {
  try {
    if (whatsAppNumber != null && whatsAppNumber.isNotEmpty) {
      return await launchUrl(
          Uri.parse("whatsapp://send?phone=$whatsAppNumber&text=$text"),
          mode: _getLaunchMode(mode));
    } else {
      return await launchUrl(Uri.parse("whatsapp://send?text=$text"),
          mode: _getLaunchMode(mode));
    }
  } catch (e) {
    return await launchUrl(
        Uri.parse(
            "https://api.whatsapp.com/send?phone=$whatsAppNumber&text=$text"),
        mode: _getLaunchMode(mode));
  }
}