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:
...
CodePudding user response:
Run flutter clean
, then re-run/re-compile your project.Hot restart or hot reload is not enough.
CodePudding user response:
This happened to me one time and it has two causes:
you didn't follow the url_launcher package's specific necessary configuration for your target devices.
you didn't delete the build folder and run your app again, first run:
flutter clean flutter pub get
And re-run your app in the emulator/device ( Not hot restart, you need to stop your app, and run it again)
Hope this helps!