This commit is contained in:
Hamza Aleghwairyeen
2024-04-03 00:05:31 +03:00
parent 02b27110df
commit ae41f1bb24
7 changed files with 48 additions and 26 deletions

View File

@@ -56,6 +56,23 @@ class LocationController extends GetxController {
print('total point is $totalPoints'); print('total point is $totalPoints');
await getLocation(); await getLocation();
// Animate camera to user location (optional)
if (Get.find<HomeCaptainController>().rideId == 'rideId') {
Get.find<MapDriverController>()
.mapController!
.animateCamera(CameraUpdate.newLatLng(LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
)));
} else {
Get.find<HomeCaptainController>()
.mapHomeCaptainController
.animateCamera(CameraUpdate.newLatLng(LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
)));
}
// if (box.read(BoxName.driverID) != null) { // if (box.read(BoxName.driverID) != null) {
await CRUD() await CRUD()
.post(link: AppLink.addCarsLocationByPassenger, payload: { .post(link: AppLink.addCarsLocationByPassenger, payload: {
@@ -71,21 +88,21 @@ class LocationController extends GetxController {
: totalDistance.toStringAsFixed(1), : totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation).toString() 'status': box.read(BoxName.statusDriverLocation).toString()
}); });
if (Get.find<HomeCaptainController>().rideId == '0') { // if (Get.find<HomeCaptainController>().rideId == '0') {
await sql.insertData({ // await sql.insertData({
'driver_id': box.read(BoxName.driverID), // 'driver_id': box.read(BoxName.driverID),
'latitude': myLocation.latitude.toString(), // 'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(), // 'longitude': myLocation.longitude.toString(),
'created_at': DateTime.now().toString(), // 'created_at': DateTime.now().toString(),
}, TableName.carLocations); // }, TableName.carLocations);
} else { // } else {
await sql.insertData({ // await sql.insertData({
'order_id': Get.find<MapDriverController>().rideId, // 'order_id': Get.find<MapDriverController>().rideId,
'created_at': DateTime.now().toString(), // 'created_at': DateTime.now().toString(),
'lat': myLocation.latitude.toString(), // 'lat': myLocation.latitude.toString(),
'lng': myLocation.longitude.toString(), // 'lng': myLocation.longitude.toString(),
}, TableName.rideLocation); // }, TableName.rideLocation);
} // }
// } // }
// //

View File

@@ -155,14 +155,14 @@ class HomeCaptainController extends GetxController {
update(); update();
} }
late GoogleMapController mapHomeCaptaiController; late GoogleMapController mapHomeCaptainController;
void onMapCreated(GoogleMapController controller) { void onMapCreated(GoogleMapController controller) {
mapHomeCaptaiController = controller; mapHomeCaptainController = controller;
controller.getVisibleRegion(); controller.getVisibleRegion();
// Animate camera to user location (optional)
controller.animateCamera( controller.animateCamera(
CameraUpdate.newLatLng(Get.find<LocationController>().myLocation), CameraUpdate.newLatLng(Get.find<LocationController>().myLocation),
); );
update();
} }
void savePeriod(Duration period) { void savePeriod(Duration period) {
@@ -212,7 +212,7 @@ class HomeCaptainController extends GetxController {
getCountRideToday(); getCountRideToday();
getAllPayment(); getAllPayment();
startPeriodicExecution(); startPeriodicExecution();
onMapCreated(mapHomeCaptaiController); onMapCreated(mapHomeCaptainController);
totalPoints = Get.find<CaptainWalletController>().totalPoints; totalPoints = Get.find<CaptainWalletController>().totalPoints;
getRefusedOrderByCaptain(); getRefusedOrderByCaptain();
// LocationController().getLocation(); // LocationController().getLocation();

View File

@@ -91,6 +91,7 @@ class MapDriverController extends GetxController {
late LatLng myLocation; late LatLng myLocation;
int remainingTimeTimerRideBegin = 60; int remainingTimeTimerRideBegin = 60;
String stringRemainingTimeRideBegin = ''; String stringRemainingTimeRideBegin = '';
String stringRemainingTimeRideBegin1 = '';
double progressTimerRideBegin = 0; double progressTimerRideBegin = 0;
late Timer timer; late Timer timer;
String? mapAPIKEY; String? mapAPIKEY;
@@ -104,7 +105,9 @@ class MapDriverController extends GetxController {
myLocation = myLocation; myLocation = myLocation;
mapController = controller; mapController = controller;
controller.getVisibleRegion(); controller.getVisibleRegion();
controller.animateCamera(
CameraUpdate.newLatLng(Get.find<LocationController>().myLocation),
);
// Set up a timer or interval to trigger the marker update every 3 seconds. // Set up a timer or interval to trigger the marker update every 3 seconds.
timer = Timer.periodic(const Duration(seconds: 1), (_) { timer = Timer.periodic(const Duration(seconds: 1), (_) {
updateMarker(); updateMarker();
@@ -603,7 +606,10 @@ class MapDriverController extends GetxController {
int seconds = remainingTimeTimerRideBegin % 60; int seconds = remainingTimeTimerRideBegin % 60;
stringRemainingTimeRideBegin = stringRemainingTimeRideBegin =
'$minutes:${seconds.toString().padLeft(2, '0')}'; '$minutes:${seconds.toString().padLeft(2, '0')}';
int minutes1 = (rideTimerFromBegin / 60).floor();
int seconds1 = rideTimerFromBegin % 60;
stringRemainingTimeRideBegin1 =
'$minutes1:${seconds1.toString().padLeft(2, '0')}';
update(); update();
} }
} }

View File

@@ -21,7 +21,7 @@ class PassengerLocationMapPage extends StatelessWidget {
Get.put(MapDriverController()); Get.put(MapDriverController());
return MyScafolld( return MyScafolld(
title: 'Map Passenger'.tr, title: Get.find<MapDriverController>().carType,
body: [ body: [
GoogleDriverMap(locationController: locationController), GoogleDriverMap(locationController: locationController),
const PassengerInfoWindow(), const PassengerInfoWindow(),

View File

@@ -89,7 +89,7 @@ GetBuilder<HomeCaptainController> leftMainMenuCaptainIcons() {
borderRadius: BorderRadius.circular(15)), borderRadius: BorderRadius.circular(15)),
child: IconButton( child: IconButton(
onPressed: () { onPressed: () {
controller.mapHomeCaptaiController controller.mapHomeCaptainController
.animateCamera(CameraUpdate.newLatLng(LatLng( .animateCamera(CameraUpdate.newLatLng(LatLng(
Get.find<LocationController>().myLocation.latitude, Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude, Get.find<LocationController>().myLocation.longitude,

View File

@@ -62,8 +62,7 @@ GetBuilder<MapDriverController> driverEndRideBar() {
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
const Icon(Icons.timer), const Icon(Icons.timer),
Text(mapDriverController.rideTimerFromBegin Text(mapDriverController.stringRemainingTimeRideBegin1),
.toStringAsFixed(0)),
const Icon(Icons.location_on), const Icon(Icons.location_on),
Text( Text(
'${mapDriverController.recentDistanceToDash.toStringAsFixed(0)} ${'KM'.tr}'), '${mapDriverController.recentDistanceToDash.toStringAsFixed(0)} ${'KM'.tr}'),

View File

@@ -30,7 +30,7 @@ class GoogleDriverMap extends StatelessWidget {
), ),
onCameraMoveStarted: () {}, onCameraMoveStarted: () {},
onCameraMove: (position) { onCameraMove: (position) {
// locationController.myLocation = position.target; locationController.myLocation = position.target;
print(position); print(position);
}, },
minMaxZoomPreference: const MinMaxZoomPreference(6, 18), minMaxZoomPreference: const MinMaxZoomPreference(6, 18),