0

I have been trying to open the whatsapp aplication from my flutter app. But it trying to opening the whatssap in my same app, instead of open the whatsapp app. And also, once it open, inmediately show my an error message. Y have tried all the possible combination that could be in internet.

 void _showWhatssap() async {

String whatsapp = '+593963631704';   

var whatsappURlAndroid = Uri.parse('https://wa.me/$whatsapp');    
    
var whatappURLIos =
    Uri.parse('https://wa.me/$whatsapp?text=${Uri.parse("hello")}');

if (Platform.isIOS) {
  // for iOS phone only
  if (await canLaunchUrl(whatappURLIos)) {
    await launchUrl(whatappURLIos);
  } else {
    ScaffoldMessenger.of(context)
        .showSnackBar(SnackBar(content: new Text("whatsapp no installed")));
  }
}
else {
  bool status  = await canLaunchUrl(whatsappURlAndroid);
  print("ESTADO: ${status}");
  if (status) {

    await launchUrl(whatsappURlAndroid);
  } else {
    ScaffoldMessenger.of(context)
        .showSnackBar(SnackBar(content: new Text("whatsapp no installed para android")));
  }
}

} }

enter image description here

Vishal Vasani
  • 647
  • 8
  • 16
PartnerTech
  • 119
  • 1
  • 9
  • Did you take a look at [this issue](https://stackoverflow.com/questions/55771211/can-any-one-tell-me-how-to-open-another-app-using-flutter)? – returnVoid Aug 09 '22 at 23:14

2 Answers2

0

using url luncher https://pub.dev/packages/url_launcher make sure u Follow the Instructions cuze it's work fine with me

void _showWhatssap() async {

var whatsappUrl ="whatsapp://send?phone=+593963631704&text=hi";
await canLaunch(whatsappUrl)? launch(whatsappUrl):print("open whatsapp app link or do a snackbar with notification that there is no whatsapp installed");

} 

and u can see this https://pub.dev/packages/whatsapp_share2

and u can check this https://pub.dev/packages/flutter_launch it's for whatsapp example

B14ck
  • 51
  • 3
0

you can use the following package to check app availability and open it.

https://pub.dev/packages/flutter_appavailability

daksh bhardwaj
  • 315
  • 4
  • 12