Launch WhatsApp from within your flutter App.

Kashif Chandio
2 min readAug 22, 2022

Flutter is emerging and latest cross platform development tool in market with a growing community.

Here I am trying to explain you how to launch WhatsApp from within your flutter App if you need it in case of users to let you text on your WhatsApp and even you want users to open direct chat without saving someone’s contact.

Here I am using url_launcher package to open WhatsApp by following url schema provided by WhatsApp official documentation.

Here is the complete url for opening whatsApp by url.

whatsapp://send?phone=923006751321&text=Hello}

Here in country code should be without ‘+’ as mentioned by whatsapp official documentation. If you writing your own number you should be known with your country code otherwise if you are asking user to enter phone number then you should probably asked them to enter country code.

You can use country_code_picker package to pick country code easily.

try {phoneNumberCode = phoneNumberCode.replaceAll(‘+’, ‘’);
//launchUrlString is method of url_launcher package and //phoneNoController.text is the number from phone number textfield
await launchUrlString(‘whatsapp://send?phone=${phoneNumberCode + phoneNoController.text}&text=${Uri.encodeFull(messageController.text)}’);} catch (e) {print(‘Error Launching WhatsApp’);}

Then all you have to do is call replaceAll on country code to replace ‘+’ with ‘’ empty string and pass it with entered number to string. Thats all. Leave rest of the things on Whatsapp. It will open WhatsApp with the given number chat opened. If no user found, WhatsApp show you a message saying no user found.

UI For it.

Hope you found it helpful.

--

--

Kashif Chandio

Flutter Developer and Passionate to Learn new Technologies and Tools