25-4/14/1

This commit is contained in:
Hamza-Ayed
2025-04-04 01:07:13 +03:00
parent 153d2f64c0
commit f3ada31b3b
88 changed files with 3231 additions and 11073 deletions

View File

@@ -81,6 +81,8 @@ class CRUD {
Map<String, dynamic>? payload,
}) async {
var s = await LoginDriverController().getJwtWallet();
final hmac = box.read(BoxName.hmac);
Log.print('hmac: ${hmac}');
var url = Uri.parse(
link,
);
@@ -89,7 +91,8 @@ class CRUD {
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer $s'
'Authorization': 'Bearer $s',
'X-HMAC-Auth': hmac.toString(),
},
);
// print(response.request);
@@ -127,6 +130,8 @@ class CRUD {
Future<dynamic> postWallet(
{required String link, Map<String, dynamic>? payload}) async {
var s = await LoginDriverController().getJwtWallet();
final hmac = box.read(BoxName.hmac);
Log.print('hmac: ${hmac}');
var url = Uri.parse(link);
try {
await LoginDriverController().getJWT();
@@ -136,7 +141,8 @@ class CRUD {
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer $s'
'Authorization': 'Bearer $s',
'X-HMAC-Auth': hmac.toString(),
},
);
// print(response.request);

View File

@@ -104,6 +104,8 @@ class LocationController extends GetxController {
return 'Cairo';
}
int _insertCounter = 0;
Future<void> startLocationUpdates() async {
if (box.read(BoxName.driverID) != null) {
if (location == null) {
@@ -117,49 +119,59 @@ class LocationController extends GetxController {
Get.find<CaptainWalletController>().totalPoints.toString();
isActive = Get.find<HomeCaptainController>().isActive;
if (isActive) {
if (double.parse(totalPoints) > -300) {
await getLocation();
if (myLocation == null) {
return;
}
// 'Latitude: ${myLocation.latitude}, Longitude: ${myLocation.longitude}');
if (isActive && double.parse(totalPoints) > -300) {
await getLocation();
if (myLocation == null) return;
String area =
getLocationArea(myLocation.latitude, myLocation.longitude);
String area =
getLocationArea(myLocation.latitude, myLocation.longitude);
if (box.read(BoxName.driverID) != null) {
await CRUD().post(
link: box.read(BoxName.serverChosen) +
'/ride/location/add.php',
payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': (speed * 3.6).toStringAsFixed(1),
'distance': totalDistance == 0 && (speed * 3.6) < 5
? '0.0'
: totalDistance < 7
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation) ?? 'off',
});
final payload = {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': (speed * 3.6).toStringAsFixed(1),
'distance': totalDistance == 0 && (speed * 3.6) < 5
? '0.0'
: totalDistance < 7
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation) ?? 'off',
};
Get.find<HomeCaptainController>()
.mapHomeCaptainController
?.animateCamera(
CameraUpdate.newLatLng(
LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
),
),
);
}
// 🔁 كل 5 ثواني - تحديث الموقع
await CRUD().post(
link:
box.read(BoxName.serverChosen) + '/ride/location/update.php',
payload: payload,
);
// 📍 كل 60 ثانية - إدخال جديد
_insertCounter++;
if (_insertCounter >= 12) {
_insertCounter = 0;
await CRUD().post(
link: box.read(BoxName.serverChosen) + '/ride/location/add.php',
payload: payload,
);
}
// 🔄 تحديث الكاميرا
Get.find<HomeCaptainController>()
.mapHomeCaptainController
?.animateCamera(
CameraUpdate.newLatLng(
LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
),
),
);
}
} catch (e) {}
} catch (e) {
print('Location update error: $e');
}
});
}
}