This commit is contained in:
Hamza-Ayed
2024-03-21 02:09:52 +03:00
parent ad062d9ad7
commit 045f7e20f0
46 changed files with 2767 additions and 877 deletions

View File

@@ -1,5 +1,6 @@
import 'dart:async';
import 'package:SEFER/constant/table_names.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
@@ -25,35 +26,46 @@ class LocationController extends GetxController {
super.onInit();
location = Location();
getLocation();
// myLocation=getLocation();
// startLocationUpdates();
totalPoints = Get.put(CaptainWalletController()).totalPoints;
}
void startLocationUpdates() async {
_locationTimer = Timer.periodic(const Duration(seconds: 5), (timer) async {
try {
totalPoints = Get.find<CaptainWalletController>().totalPoints;
Future<void> startLocationUpdates() async {
if (box.read(BoxName.driverID) != null) {
_locationTimer =
Timer.periodic(const Duration(seconds: 5), (timer) async {
try {
totalPoints = Get.find<CaptainWalletController>().totalPoints;
// if (isActive) {
if (double.parse(totalPoints) > -500) {
print('total point is $totalPoints');
await getLocation();
// if (isActive) {
if (double.parse(totalPoints) > -300) {
print('total point is $totalPoints');
await getLocation();
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'status': box.read(BoxName.statusDriverLocation).toString()
});
await CRUD()
.post(link: AppLink.addCarsLocationByPassenger, payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'status': box.read(BoxName.statusDriverLocation).toString()
});
await sql.insertData({
'driver_id': box.read(BoxName.driverID),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'created_at': DateTime.now().toString(),
}, TableName.carLocations);
//
}
// }
} catch (e) {
// Handle the error gracefully
print('Error during location updates: $e');
}
// }
} catch (e) {
// Handle the error gracefully
print('Error during location updates: $e');
}
});
});
}
}
void stopLocationUpdates() {