launchWhatsApp static method

void launchWhatsApp(
  1. BuildContext context, {
  2. required String phoneNumber,
  3. String? msg,
})

Implementation

static void launchWhatsApp(
  BuildContext context, {
  required String phoneNumber,
  String? msg,
}) async {
  String whatsappUrl = "whatsapp://send?phone=$phoneNumber";
  if (msg != null) {
    whatsappUrl += "&text=$msg";
  }
  if (await canLaunchUrl(Uri.parse(whatsappUrl))) {
    launchUrl(Uri.parse(whatsappUrl));
  } else {
    debugPrint("Could not launch Email with $phoneNumber");
  }
}