Files
intaleq/siro_service/lib/controller/functions/launch.dart
T
Hamza-AyedandClaude Opus 5 92dc6b3641 chore: استيراد أولي من سيرو (ecfe7568) — بلا أي تعديل
نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق».
نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا
`cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules ·
.dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore.

هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً
مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ.

⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا
صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم
توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:10:29 +03:00

132 lines
3.6 KiB
Dart

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))) {
launchUrl(Uri.parse(url));
} else {}
}
Future<void> makePhoneCall(String phoneNumber) async {
final cleanPhone = phoneNumber.replaceAll(RegExp(r'[^0-9+]'), '');
final Uri launchUri = Uri(
scheme: 'tel',
path: cleanPhone,
);
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:$cleanPhone';
break;
case 'sms':
url = 'sms:$cleanPhone?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
url =
'https://api.whatsapp.com/send?phone=$phone&text=${Uri.encodeComponent(message)}';
break;
case 'email':
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
return;
}
} else if (Platform.isAndroid) {
switch (method) {
case 'phone':
url = 'tel:$cleanPhone';
break;
case 'sms':
url = 'sms:$cleanPhone?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
// Check if WhatsApp is installed
final bool whatsappInstalled =
await canLaunchUrl(Uri.parse('whatsapp://'));
if (whatsappInstalled) {
url =
'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=$phone&text=${Uri.encodeComponent(message)}';
}
break;
case 'email':
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
return;
}
} else {
return;
}
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));
} else {}
}