Reputation: 17
ElevatedButton(
onPressed:() {
launchWhatsapp(phoneNum,message);
},
child: Text("Message the Buyer",
style: TextStyle(
fontWeight: FontWeight.w400
),
),
),
So this is my button code
launchWhatsapp(String number,String text) async{
String url = "https://wa.me/${number}";
if(await canLaunchUrlString(url)){
await launchUrlString(url);
}
and this is my function method. I used url_laucher to make it work but it will redirect to the browser and show this Image Error but when I try to copy the same link to the browser it works but when trying to open from my app it will show the error as shown in the picture.
Upvotes: 1
Views: 2653
Reputation: 14785
Try below code
Your function:
whatsApp() {
return launchUrl(
Uri.parse(
//'https://wa.me/1234567890' //you use this url also
'whatsapp://send?phone=1234567890',//put your number here
),
);
}
Your Widget:
ElevatedButton(
onPressed: () {
whatsApp();
},
child: Text(
"Message the Buyer",
style: TextStyle(fontWeight: FontWeight.w400),
),
),
set internet permission to your AndroidManifest.xml
file path = project_name/android/app/src/main/AndroidManifest.xml
add below line above of application tag
<uses-permission android:name="android.permission.INTERNET"/>
Upvotes: 7