This commit is contained in:
Hamza-Ayed
2024-06-09 17:31:25 +03:00
parent 97c0b5d1bd
commit b5badb8f2e
13 changed files with 704 additions and 96 deletions

View File

@@ -18,19 +18,17 @@ void launchCommunication(
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=$message';
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
url = 'https://api.whatsapp.com/send?phone=$contactInfo&text=$message';
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
break;
case 'email':
url = 'mailto:$contactInfo?subject=Subject&body=$message';
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
print('Method not supported on iOS');
return;
@@ -40,19 +38,27 @@ void launchCommunication(
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=$message';
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
url = 'whatsapp://send?phone=$contactInfo&text=$message';
// 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=$message';
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
print('Method not supported on Android');
return;
@@ -62,8 +68,10 @@ void launchCommunication(
return;
}
print('Launching URL: $url');
if (await canLaunchUrl(Uri.parse(url))) {
launchUrl(Uri.parse(url));
await launchUrl(Uri.parse(url));
} else {
print('Could not launch $url');
}