0

I am building an flutter web application that has to be able to send message on specific WhatsApp Business number and WhatsApp number. What exactly am I supposed to do? If the user's device has either WhatsApp or WhatsApp Business, he opens it. But my problem is that if user's device has both WhatsApp and WhatsApp business, I want one to open on one condition.

var whatsappURlAndroid = "https://wa.me/$whatsappNumber/?text=Hi";
var whatappURLIos ="https://wa.me/$whatsappNumber?text=${Uri.parse("hello")}";
var webWhatsapp= "https://web.whatsapp.com/send?phone=$whatsappNumber&text=Hello";

if (defaultTargetPlatform == TargetPlatform.iOS) {
  await launch(whatappURLIos, forceSafariVC: false);
}else if(defaultTargetPlatform == TargetPlatform.android){
  await launch(whatsappURlAndroid);
}
else{
  await launch(webWhatsapp);
}
  • https://stackoverflow.com/questions/64185403/linking-url-for-whatsapp-business-when-both-whatsapp-and-whatsapp-business-appli and https://stackoverflow.com/questions/59301756/how-to-open-wa-me-link-in-whatsapp-business-app-instead-of-personal-whatsapp-on seems to indicate the user must change their config to manually pick the handler. – Martheen Apr 25 '22 at 06:08

1 Answers1

0
FocusManager.instance.primaryFocus?.unfocus();
var whatsappUrl = "whatsapp://send?phone=${_countryCodeController.text +
    _phoneController.text}" +
    "&text=${Uri.encodeComponent(_messageController.text)}";
try {
    launch(whatsappUrl);
} catch (e) {
    // To handle error and display error message:
    Helper.errorSnackBar(
    context: context, message: "Unable to open whatsapp");
}
Toni
  • 1,555
  • 4
  • 15
  • 23