Update: 2026-06-15 01:37:40
This commit is contained in:
@@ -42,6 +42,7 @@ class BoxName {
|
||||
static const String addHome = 'addHome';
|
||||
static const String placesDestination = 'placesDestination';
|
||||
static const String tipPercentage = 'tipPercentage';
|
||||
static const String lastLocationPush = 'lastLocationPush';
|
||||
|
||||
static const String faceDetectTimes = "faceDetectTimes";
|
||||
static const String sosPhonePassenger = "sosPhonePassenger";
|
||||
|
||||
@@ -404,6 +404,7 @@ static String get loginFirstTime => "$server/loginFirstTime.php";
|
||||
static String get getTesterApp => "$auth/Tester/getTesterApp.php";
|
||||
static String get updateTesterApp => "$auth/Tester/updateTesterApp.php";
|
||||
static String get signUp => "$auth/signup.php";
|
||||
static String get savePassengerLocation => "$auth/save_passenger_location.php";
|
||||
static String get sendVerifyEmail => "$auth/sendVerifyEmail.php";
|
||||
static String get loginFromGooglePassenger => "$auth/loginFromGooglePassenger.php";
|
||||
static String get loginUsingCredentialsWithoutGooglePassenger => "$auth/loginUsingCredentialsWithoutGooglePassenger.php";
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:siro_rider/constant/api_key.dart';
|
||||
import 'package:siro_rider/controller/firebase/firbase_messge.dart';
|
||||
import 'package:siro_rider/views/auth/otp_page.dart';
|
||||
@@ -422,6 +423,7 @@ class LoginController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
sendPassengerLocation();
|
||||
Get.offAll(() => const MapPagePassenger());
|
||||
} catch (e) {
|
||||
addError('$e', 'loginUsingCredentials');
|
||||
@@ -484,6 +486,7 @@ class LoginController extends GetxController {
|
||||
|
||||
await storage.write(key: BoxName.fingerPrint, value: fingerPrint);
|
||||
|
||||
sendPassengerLocation();
|
||||
Get.offAll(() => const MapPagePassenger());
|
||||
} else {
|
||||
Get.offAll(() => LoginPage());
|
||||
@@ -539,4 +542,76 @@ class LoginController extends GetxController {
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// sendPassengerLocation: تسجيل موقع فتح التطبيق للراكب
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
Future<void> sendPassengerLocation() async {
|
||||
try {
|
||||
final String? passengerID = box.read(BoxName.passengerID)?.toString();
|
||||
if (passengerID == null || passengerID.isEmpty) {
|
||||
Log.print("sendPassengerLocation: No passenger ID found, skipping.");
|
||||
return;
|
||||
}
|
||||
|
||||
// ── [THROTTLING] تحديث الموقع مرة كل 12 ساعة فقط لتقليل الضغط ──
|
||||
final String cacheKey = '${BoxName.lastLocationPush}_$passengerID';
|
||||
final String? lastUploadStr = box.read(cacheKey);
|
||||
if (lastUploadStr != null) {
|
||||
final DateTime lastUpload = DateTime.parse(lastUploadStr);
|
||||
final Duration diff = DateTime.now().difference(lastUpload);
|
||||
if (diff.inHours < 12) {
|
||||
Log.print("sendPassengerLocation: Location uploaded recently (${diff.inHours}h ago). Skipping.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// تحقق من تفعيل خدمات الموقع الجغرافي
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
Log.print("sendPassengerLocation: Location service disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// التحقق من الصلاحيات والسكوت الممنهج لتفادي النوافذ المزعجة
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
Log.print("sendPassengerLocation: Permission is denied. Skipping silently.");
|
||||
return;
|
||||
}
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
Log.print("sendPassengerLocation: Permission permanently denied. Skipping silently.");
|
||||
return;
|
||||
}
|
||||
|
||||
// جلب الموقع الحالي بمهلة 5 ثوانٍ
|
||||
final Position position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.medium,
|
||||
timeLimit: const Duration(seconds: 5),
|
||||
);
|
||||
|
||||
Log.print("sendPassengerLocation: Got location: ${position.latitude}, ${position.longitude}");
|
||||
|
||||
// إرسال البيانات إلى السيرفر
|
||||
final response = await CRUD().post(
|
||||
link: AppLink.savePassengerLocation,
|
||||
payload: {
|
||||
'latitude': position.latitude.toString(),
|
||||
'longitude': position.longitude.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
Log.print("sendPassengerLocation response: $response");
|
||||
|
||||
if (response != 'failure' && response != null) {
|
||||
final decoded = response is Map ? response : jsonDecode(response.toString());
|
||||
if (decoded['status'] == 'success') {
|
||||
box.write(cacheKey, DateTime.now().toIso8601String());
|
||||
Log.print("sendPassengerLocation: Location logged and cached successfully.");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print("sendPassengerLocation error: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user