Update: 2026-06-28 23:14:46
This commit is contained in:
@@ -119,18 +119,69 @@ class MainController extends GetxController {
|
||||
// await getDriverData();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> launchCommunication(
|
||||
String method, String contactInfo, String message) async {
|
||||
// رقّم فقط (بدون + أو مسافات)
|
||||
final phone = contactInfo.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
final country = box.read('countryCode')?.toString() ?? 'Jordan';
|
||||
final phone = _formatPhoneNumberForCommunication(contactInfo, country);
|
||||
final encodedMsg = Uri.encodeComponent(message);
|
||||
|
||||
Uri? uri;
|
||||
|
||||
Reference in New Issue
Block a user