I have used this code to send a message to WhatsApp using flutter with url_launcher,
void sendCodeByWhatsApp({
required int phone,
required String message,
}) async {
String url() {
if (Platform.isAndroid) {
return "whatsapp://send?phone=$phone&text=${Uri.parse(message)}";
} else {
return "https://wa.me/$phone?text=${Uri.parse(message)}";
}
}
if (await canLaunchUrl(Uri.parse(url()))) {
print("https://wa.me/$phone/?text=$message");
await launchUrl(Uri.parse(url()));
} else {
throw 'Could not launch ${url()}';
}
}
how can I edit it to send a message to the Telegram or viber for example?
2
Answers
Try this one. https://telegram.me/905555555555 it works. I did not test all possibilities btw.
try https://pub.dev/packages/share_plus
This opens up a wide range of option to send text from flutter app to another app.
More over the implementation is quite user friendly as well. For instance
Share.share(‘check out my website https://example.com‘);