25-12-1/1
This commit is contained in:
@@ -51,7 +51,7 @@ class HomeCaptainController extends GetxController {
|
||||
String totalMoneyInSEFER = '0';
|
||||
String totalDurationToday = '0';
|
||||
Timer? timer;
|
||||
late LatLng myLocation = const LatLng(32, 36);
|
||||
late LatLng myLocation = const LatLng(33.5138, 36.2765);
|
||||
String totalPoints = '0';
|
||||
String countRefuse = '0';
|
||||
bool mapType = false;
|
||||
@@ -99,7 +99,7 @@ class HomeCaptainController extends GetxController {
|
||||
|
||||
isActive = !isActive;
|
||||
if (isActive) {
|
||||
if (double.parse(totalPoints) > -300) {
|
||||
if (double.parse(totalPoints) > -30000) {
|
||||
locationController.startLocationUpdates();
|
||||
HapticFeedback.heavyImpact();
|
||||
// locationBackController.startBackLocation();
|
||||
@@ -188,22 +188,25 @@ class HomeCaptainController extends GetxController {
|
||||
|
||||
// late GoogleMapController mapHomeCaptainController;
|
||||
GoogleMapController? mapHomeCaptainController;
|
||||
// final locationController = Get.find<LocationController>();
|
||||
|
||||
// --- FIX 2: Smart Map Creation ---
|
||||
void onMapCreated(GoogleMapController controller) {
|
||||
mapHomeCaptainController = controller;
|
||||
controller.getVisibleRegion();
|
||||
// Animate camera to user location (optional)
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLng(Get.find<LocationController>().myLocation),
|
||||
);
|
||||
}
|
||||
|
||||
// قم بإنشائه مباشرة
|
||||
// final MapController mapController = MapController();
|
||||
// bool isMapReady = false;
|
||||
// void onMapReady() {
|
||||
// isMapReady = true;
|
||||
// print("Map is ready to be moved!");
|
||||
// }
|
||||
// Check actual location before moving camera
|
||||
var currentLoc = locationController.myLocation;
|
||||
if (currentLoc.latitude != 0 && currentLoc.longitude != 0) {
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLng(currentLoc),
|
||||
);
|
||||
} else {
|
||||
// Optional: Move to default city view instead of ocean
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLngZoom(myLocation, 10),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void savePeriod(Duration period) {
|
||||
final periods = box.read<List<dynamic>>(BoxName.periods) ?? [];
|
||||
@@ -234,7 +237,14 @@ class HomeCaptainController extends GetxController {
|
||||
getlocation() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
// This ensures we try to get a fix, but map doesn't crash if it fails
|
||||
await Get.find<LocationController>().getLocation();
|
||||
|
||||
var loc = Get.find<LocationController>().myLocation;
|
||||
if (loc.latitude != 0) {
|
||||
myLocation = loc;
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
@@ -267,7 +277,7 @@ class HomeCaptainController extends GetxController {
|
||||
void onInit() async {
|
||||
// await locationBackController.requestLocationPermission();
|
||||
Get.put(FirebaseMessagesController());
|
||||
// addToken();
|
||||
addToken();
|
||||
await getlocation();
|
||||
onButtonSelected();
|
||||
getDriverRate();
|
||||
@@ -283,61 +293,27 @@ class HomeCaptainController extends GetxController {
|
||||
getRefusedOrderByCaptain();
|
||||
box.write(BoxName.statusDriverLocation, 'off');
|
||||
locationController.addListener(() {
|
||||
// فقط إذا كان السائق "متصل" والخريطة جاهزة
|
||||
// Only animate if active, map is ready, AND location is valid (not 0,0)
|
||||
if (isActive && mapHomeCaptainController != null) {
|
||||
mapHomeCaptainController!.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: locationController.myLocation, // الموقع الجديد
|
||||
zoom: 17.5,
|
||||
tilt: 50.0,
|
||||
bearing: locationController.heading, // اتجاه السيارة
|
||||
var loc = locationController.myLocation;
|
||||
|
||||
if (loc.latitude != 0 && loc.longitude != 0) {
|
||||
mapHomeCaptainController!.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: loc,
|
||||
zoom: 17.5,
|
||||
tilt: 50.0,
|
||||
bearing: locationController.heading,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
// LocationController().getLocation();
|
||||
super.onInit();
|
||||
}
|
||||
// void getRefusedOrderByCaptain() async {
|
||||
// // Get today's date in YYYY-MM-DD format
|
||||
// String today = DateTime.now().toString().substring(0, 10);
|
||||
|
||||
// String driverId = box.read(BoxName.driverID).toString();
|
||||
|
||||
// String customQuery = '''
|
||||
// SELECT COUNT(*) AS count
|
||||
// FROM ${TableName.driverOrdersRefuse}
|
||||
// WHERE driver_id = '$driverId'
|
||||
// AND DATE(created_at) = '$today'
|
||||
// ''';
|
||||
|
||||
// try {
|
||||
// List<Map<String, dynamic>> results =
|
||||
// await sql.getCustomQuery(customQuery);
|
||||
// countRefuse = results[0]['count'].toString();
|
||||
// update();
|
||||
// if (int.parse(countRefuse) > 3) {
|
||||
// box.write(BoxName.statusDriverLocation, 'on');
|
||||
// locationController.stopLocationUpdates();
|
||||
// Get.defaultDialog(
|
||||
// // backgroundColor: CupertinoColors.destructiveRed,
|
||||
// barrierDismissible: false,
|
||||
// title: 'You Are Stopped For this Day !'.tr,
|
||||
// content: Text(
|
||||
// 'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
|
||||
// .tr,
|
||||
// style: AppStyle.title,
|
||||
// ),
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'Ok , See you Tomorrow'.tr,
|
||||
// onPressed: () => Get.back()));
|
||||
// } else {
|
||||
// box.write(BoxName.statusDriverLocation, 'off');
|
||||
// }
|
||||
// } catch (e) {}
|
||||
// }
|
||||
|
||||
addToken() async {
|
||||
String? fingerPrint = await storage.read(key: BoxName.fingerPrint);
|
||||
@@ -346,14 +322,8 @@ class HomeCaptainController extends GetxController {
|
||||
'captain_id': (box.read(BoxName.driverID)).toString(),
|
||||
'fingerPrint': (fingerPrint).toString()
|
||||
};
|
||||
Log.print('payload: ${payload}');
|
||||
// Log.print('payload: ${payload}');
|
||||
CRUD().post(link: AppLink.addTokensDriver, payload: payload);
|
||||
|
||||
await CRUD().post(
|
||||
link: "${AppLink.paymentServer}/ride/firebase/addDriver.php",
|
||||
payload: payload);
|
||||
// MapDriverController().driverCallPassenger();
|
||||
// box.write(BoxName.statusDriverLocation, 'off');
|
||||
}
|
||||
|
||||
getPaymentToday() async {
|
||||
@@ -468,6 +438,7 @@ class HomeCaptainController extends GetxController {
|
||||
void dispose() {
|
||||
activeTimer?.cancel();
|
||||
stopTimer();
|
||||
mapHomeCaptainController?.dispose(); // Dispose controller
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user