Update: 2026-06-28 23:14:46

This commit is contained in:
Hamza-Ayed
2026-06-28 23:14:46 +03:00
parent 0b36566343
commit 1b6e172a4a
10 changed files with 428 additions and 79 deletions

View File

@@ -1,5 +1,49 @@
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';
import 'package:siro_service/main.dart';
String _formatPhoneNumberForCommunication(String rawPhone, String country) {
String digits = rawPhone.replaceAll(RegExp(r'[^0-9]'), '');
if (digits.startsWith('00')) {
digits = digits.substring(2);
}
if (country == 'Jordan') {
if (digits.startsWith('962') && digits.length >= 12) {
return digits;
}
if (digits.startsWith('0')) {
digits = digits.substring(1);
}
if (!digits.startsWith('962')) {
digits = '962$digits';
}
} else if (country == 'Egypt') {
if (digits.startsWith('20') && digits.length >= 11) {
return digits;
}
if (digits.startsWith('0')) {
digits = digits.substring(1);
}
if (!digits.startsWith('20')) {
digits = '20$digits';
}
} else if (country == 'Syria') {
if (digits.startsWith('963') && digits.length >= 11) {
return digits;
}
if (digits.startsWith('0')) {
digits = digits.substring(1);
}
if (!digits.startsWith('963')) {
digits = '963$digits';
}
} else {
if (digits.startsWith('0') && digits.length > 5) {
digits = digits.substring(1);
}
}
return digits;
}
void showInBrowser(String url) async {
if (await canLaunchUrl(Uri.parse(url))) {
@@ -8,28 +52,39 @@ void showInBrowser(String url) async {
}
Future<void> makePhoneCall(String phoneNumber) async {
final cleanPhone = phoneNumber.replaceAll(RegExp(r'[^0-9+]'), '');
final Uri launchUri = Uri(
scheme: 'tel',
path: phoneNumber,
path: cleanPhone,
);
await launchUrl(launchUri);
if (await canLaunchUrl(launchUri)) {
await launchUrl(launchUri);
} else {
final String telUrl = 'tel:$cleanPhone';
if (await canLaunchUrl(Uri.parse(telUrl))) {
await launchUrl(Uri.parse(telUrl));
}
}
}
void launchCommunication(
String method, String contactInfo, String message) async {
String url;
final cleanPhone = contactInfo.replaceAll(RegExp(r'[^0-9+]'), '');
final country = box.read('countryCode')?.toString() ?? 'Jordan';
final phone = _formatPhoneNumberForCommunication(contactInfo, country);
if (Platform.isIOS) {
switch (method) {
case 'phone':
url = 'tel:$contactInfo';
url = 'tel:$cleanPhone';
break;
case 'sms':
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
url = 'sms:$cleanPhone?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
'https://api.whatsapp.com/send?phone=$phone&text=${Uri.encodeComponent(message)}';
break;
case 'email':
url =
@@ -41,10 +96,10 @@ void launchCommunication(
} else if (Platform.isAndroid) {
switch (method) {
case 'phone':
url = 'tel:$contactInfo';
url = 'tel:$cleanPhone';
break;
case 'sms':
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
url = 'sms:$cleanPhone?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
// Check if WhatsApp is installed
@@ -52,11 +107,11 @@ void launchCommunication(
await canLaunchUrl(Uri.parse('whatsapp://'));
if (whatsappInstalled) {
url =
'whatsapp://send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
'whatsapp://send?phone=$phone&text=${Uri.encodeComponent(message)}';
} else {
// Provide an alternative action, such as opening the WhatsApp Web API
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
'https://api.whatsapp.com/send?phone=$phone&text=${Uri.encodeComponent(message)}';
}
break;
case 'email':