Vrusti Patel
Vrusti Patel

Reputation: 574

How to send message on specific number (Restaurant number - For food ordering) on whatsapp from my flutter app?

launchWhatsapp(String mobileNumber,BuildContext context) async {
  var whatsapp = mobileNumber;
  var whatsappAndroid =Uri.parse("whatsapp://send?phone=$whatsapp&text=hello");
  if (await canLaunchUrl(whatsappAndroid)) {
    await launchUrl(whatsappAndroid);
  } else {
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(
        content: Text("WhatsApp is not installed on the device"),
      ),
    );
  }
}

Here, I have used url_launcher plugin,

https://pub.dev/packages/url_launcher

But the mobile number is fixed for all time, mobileNumber = "9876543211"

Now, I want to redirect on whatsapp and open chat on this number for food ordering. so everytime number will be same.

By launchWhatsapp method it redirect me on whatsapp but it shows me that, this number is not registered or saved in your contacts. How do I open chat screen on whatsapp from any device from my flutter app.

Upvotes: 1

Views: 90

Answers (2)

Vrusti Patel
Vrusti Patel

Reputation: 574

Just put a country code as prefix of your mobile number it will work.

  var whatsapp = mobileNumber;

I just did mistake of passing only number. with that, you have to pass country code as well.

  var whatsapp = "+912345678999";

Upvotes: 1

Kimiya Zargari
Kimiya Zargari

Reputation: 367

You have to give it the full correct number containing the country code

Upvotes: 0

Related Questions