Update: 2026-06-12 22:40:40

This commit is contained in:
Hamza-Ayed
2026-06-12 22:40:40 +03:00
parent f907212c57
commit 0ae368dbc8
24 changed files with 1197 additions and 303 deletions

View File

@@ -1,5 +1,11 @@
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:intaleq_maps/intaleq_maps.dart';
import 'package:siro_driver/constant/box_name.dart';
import 'package:siro_driver/constant/country_polygons.dart';
import 'package:siro_driver/constant/city_polygons.dart';
import 'package:siro_driver/main.dart';
import '../../print.dart';
class CountryLogic {
/// Formats the phone number based on the country's dialing rules.
@@ -91,4 +97,99 @@ class CountryLogic {
final country = box.read(BoxName.countryCode) ?? 'Syria';
return formatPhone(cleanPhone, country);
}
/// التحقق مما إذا كانت نقطة داخل مضلع (Ray Casting Algorithm)
static bool isPointInPolygon(LatLng point, List<LatLng> polygon) {
int intersections = 0;
for (int i = 0; i < polygon.length; i++) {
final v1 = polygon[i];
final v2 = polygon[(i + 1) % polygon.length];
if ((v1.latitude <= point.latitude && v2.latitude > point.latitude) ||
(v2.latitude <= point.latitude && v1.latitude > point.latitude)) {
final t = (point.latitude - v1.latitude) / (v2.latitude - v1.latitude);
if (point.longitude <
v1.longitude + t * (v2.longitude - v1.longitude)) {
intersections++;
}
}
}
return intersections % 2 != 0;
}
/// كشف الدولة تلقائياً عبر الموقع الجغرافي
/// باستخدام مضلعات الدول المحددة في CountryPolygons
/// تعيد 'Syria' | 'Egypt' | 'Jordan' | null (في حال الفشل)
static Future<String?> detectByLocation() async {
try {
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
Log.print('[CountryLogic] GPS غير مفعل');
return null;
}
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
Log.print('[CountryLogic] رفض الإذن');
return null;
}
}
if (permission == LocationPermission.deniedForever) return null;
final pos = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
timeLimit: const Duration(seconds: 8),
);
final point = LatLng(pos.latitude, pos.longitude);
// فحص المضلعات بالترتيب: Jordan → Syria → Egypt
if (isPointInPolygon(point, CountryPolygons.jordanBoundary)) {
return 'Jordan';
}
if (isPointInPolygon(point, CountryPolygons.syriaBoundary)) {
return 'Syria';
}
if (isPointInPolygon(point, CountryPolygons.egyptBoundary)) {
return 'Egypt';
}
Log.print('[CountryLogic] الموقع خارج جميع المضلعات');
} catch (e) {
Log.print('[CountryLogic] detectByLocation error: $e');
}
return null;
}
/// تهيئة الدولة عند بدء التطبيق
/// إذا لم تكن الدولة محددة مسبقاً → يكشفها عبر الموقع
/// إذا فشل الكشف → Jordan كخيار افتراضي
static Future<void> initializeCountry() async {
final existing = box.read(BoxName.countryCode);
if (existing != null && existing.toString().isNotEmpty) {
Log.print('[CountryLogic] الدولة موجودة مسبقاً: $existing');
return;
}
Log.print('[CountryLogic] كشف الدولة عبر الموقع...');
final country = await detectByLocation();
if (country != null) {
box.write(BoxName.countryCode, country);
Log.print('[CountryLogic] تم الكشف: $country');
} else {
box.write(BoxName.countryCode, 'Jordan');
Log.print('[CountryLogic] افتراضي: Jordan');
}
}
/// إرجاع مضلع المدينة بناءً على الدولة الحالية
static List<LatLng> getCurrentCityPolygon() {
final country = box.read(BoxName.countryCode) ?? 'Jordan';
if (country == 'Syria') return CityPolygons.damascusPolygon;
if (country == 'Egypt') return CityPolygons.cairoPolygon;
return CityPolygons.ammanPolygon;
}
}

View File

@@ -189,7 +189,7 @@ class AI extends GetxController {
// DeviceController().getDeviceSerialNumber();
box.write(BoxName.phoneVerified, true);
Get.find<LoginDriverController>().loginWithGoogleCredential(
Get.find<LoginDriverController>().loginDriver(
box.read(BoxName.driverID).toString(),
box.read(BoxName.emailDriver).toString(),
);

View File

@@ -46,7 +46,7 @@ class SmsEgyptController extends GetxController {
('+2${Get.find<RegisterCaptainController>().phoneController.text}'));
box.write(BoxName.phoneVerified, '1');
await Get.put(LoginDriverController()).loginWithGoogleCredential(
await Get.put(LoginDriverController()).loginDriver(
box.read(BoxName.driverID).toString(),
(box.read(BoxName.emailDriver).toString()),
);