This commit is contained in:
Hamza-Ayed
2024-05-27 13:21:14 +03:00
parent 3ff0eace3f
commit 6f3c8b975e
23 changed files with 213 additions and 171 deletions

View File

@@ -13,24 +13,24 @@ void launchCommunication(
String method, String contactInfo, String message) async {
String url;
// Encode the message
String encodedMessage = Uri.encodeComponent(message);
if (Platform.isIOS) {
switch (method) {
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=$message';
url = 'sms:$contactInfo?body=$encodedMessage';
break;
case 'whatsapp':
url = 'https://api.whatsapp.com/send?phone=$contactInfo&text=$message';
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=$encodedMessage';
break;
case 'email':
url = 'mailto:$contactInfo?subject=Subject&body=$message';
url = 'mailto:$contactInfo?subject=Subject&body=$encodedMessage';
break;
default:
print('Method not supported on iOS');
return;
@@ -40,19 +40,15 @@ void launchCommunication(
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=$message';
url = 'sms:$contactInfo?body=$encodedMessage';
break;
case 'whatsapp':
url = 'whatsapp://send?phone=$contactInfo&text=$message';
url = 'whatsapp://send?phone=$contactInfo&text=$encodedMessage';
break;
case 'email':
url = 'mailto:$contactInfo?subject=Subject&body=$message';
url = 'mailto:$contactInfo?subject=Subject&body=$encodedMessage';
break;
default:
print('Method not supported on Android');
return;
@@ -62,8 +58,8 @@ void launchCommunication(
return;
}
if (await canLaunchUrl(Uri.parse(url))) {
launchUrl(Uri.parse(url));
if (await canLaunch(url)) {
await launch(url);
} else {
print('Could not launch $url');
}