I'm trying to send a whatsapp message from my flutter app but I get the error: Unhandled Exception: MissingPluginException(No implementation found for method launch on channel plugins.flutter.io/url_launcher_android). Everything I found through my research did not work with me. please help me please.
void openWhatsapp(
{required BuildContext context,
required String text,
required String number}) async {
var whatsapp = number; //+92xx enter like this
var whatsappURlAndroid =
"whatsapp://send?phone=" + whatsapp + "&text=$text";
var whatsappURLIos = "https://wa.me/$whatsapp?text=${Uri.tryParse(text)}";
if (Platform.isIOS) {
// for iOS phone only
if (await canLaunchUrl(Uri.parse(whatsappURLIos))) {
await launchUrl(Uri.parse(
whatsappURLIos,
));
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Whatsapp not installed")));
}
} else {
// android , web
if (await canLaunchUrl(Uri.parse(whatsappURlAndroid))) {
await launchUrl(Uri.parse(whatsappURlAndroid));
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Whatsapp not installed")));
}
}
}
I tried:
...