This commit is contained in:
Hamza-Ayed
2024-06-09 11:42:30 +03:00
parent 27a7ff5f21
commit 8bae9bb284
6 changed files with 121 additions and 70 deletions

View File

@@ -13,23 +13,21 @@ 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=$encodedMessage';
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=$encodedMessage';
'https://api.whatsapp.com/send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
break;
case 'email':
url = 'mailto:$contactInfo?subject=Subject&body=$encodedMessage';
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
print('Method not supported on iOS');
@@ -41,13 +39,25 @@ void launchCommunication(
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=$encodedMessage';
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
url = 'whatsapp://send?phone=$contactInfo&text=$encodedMessage';
// Check if WhatsApp is installed
final bool whatsappInstalled =
await canLaunchUrl(Uri.parse('whatsapp://'));
if (whatsappInstalled) {
url =
'whatsapp://send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
} else {
print('WhatsApp is not installed on this device.');
// Provide an alternative action, such as opening the WhatsApp Web API
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
}
break;
case 'email':
url = 'mailto:$contactInfo?subject=Subject&body=$encodedMessage';
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
print('Method not supported on Android');
@@ -58,7 +68,7 @@ void launchCommunication(
return;
}
print('Launching URL: $url'); // Add this line for debugging
print('Launching URL: $url');
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));