sendWhatsAppMessage method

void sendWhatsAppMessage({
  1. String? phone,
})

? Send Whats App Message With the passed String as Message Body

Implementation

void sendWhatsAppMessage({
  String? phone,
}) async {
  String url() {
    if (Platform.isIOS) {
      if (phone != null) {
        return 'whatsapp://wa.me/$phone?text=${Uri.parse(this)}';
      } else {
        return 'whatsapp://wa.me/?text=${Uri.parse(this)}';
      }
    } else {
      if (phone != null) {
        return 'whatsapp://send?phone=$phone&text=${Uri.parse(this)}';
      } else {
        return 'whatsapp://send?text=${Uri.parse(this)}';
      }
    }
  }

  if (await canLaunchUrl(
    Uri.parse(url()),
  )) {
    await launchUrl(Uri.parse(url()));
  } else {
    throw Exception('Could not launchUrl ${url()}');
  }
}