diff --git a/android/app/build.gradle b/android/app/build.gradle
index 7f19805..58f1122 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -42,10 +42,10 @@ android {
// Merged the two defaultConfig sections into one. This is the correct way.
defaultConfig {
applicationId = "com.intaleq_driver"
- minSdk = 23
+ minSdkVersion = 23
targetSdk = 36
- versionCode = 36
- versionName = '1.0.36' // I've used the higher version name
+ versionCode = 47
+ versionName = '1.0.47' // I've used the higher version name
multiDexEnabled = true
ndk {
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index f76d10a..52809f5 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -1,177 +1,106 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/assets/images/shamcashsend.png b/assets/images/shamcashsend.png
new file mode 100644
index 0000000..0814517
Binary files /dev/null and b/assets/images/shamcashsend.png differ
diff --git a/lib/constant/box_name.dart b/lib/constant/box_name.dart
index ffddc57..e1ded10 100755
--- a/lib/constant/box_name.dart
+++ b/lib/constant/box_name.dart
@@ -11,6 +11,7 @@ class BoxName {
"rideArgumentsFromBackground";
static const String FCM_PRIVATE_KEY = "FCM_PRIVATE_KEY";
static const String hmac = "hmac";
+ static const String ttsEnabled = "ttsEnabled";
static const String walletType = "walletType";
static const String fingerPrint = "fingerPrint";
static const String updateInterval = "updateInterval";
diff --git a/lib/controller/auth/captin/invit_controller.dart b/lib/controller/auth/captin/invit_controller.dart
index ab16045..e12a904 100755
--- a/lib/controller/auth/captin/invit_controller.dart
+++ b/lib/controller/auth/captin/invit_controller.dart
@@ -326,15 +326,45 @@ Download the Intaleq app now and enjoy your ride!
return input; // Fallback for unrecognized formats
}
+ String normalizeSyrianPhone(String input) {
+ String phone = input.trim();
+
+ // احذف كل شيء غير أرقام
+ phone = phone.replaceAll(RegExp(r'[^0-9]'), '');
+
+ // إذا يبدأ بـ 0 → احذفها
+ if (phone.startsWith('0')) {
+ phone = phone.substring(1);
+ }
+
+ // إذا يبدأ بـ 963 مكررة → احذف التكرار
+ while (phone.startsWith('963963')) {
+ phone = phone.substring(3);
+ }
+
+ // إذا يبدأ بـ 963 ولكن داخله كمان 963 → خليه مرة واحدة فقط
+ if (phone.startsWith('963') && phone.length > 12) {
+ phone = phone.substring(phone.length - 9); // آخر 9 أرقام
+ }
+
+ // الآن إذا كان بلا 963 → أضفها
+ if (!phone.startsWith('963')) {
+ phone = '963' + phone;
+ }
+
+ return phone;
+ }
+
/// Sends an invitation to a potential new driver.
void sendInvite() async {
if (invitePhoneController.text.isEmpty) {
mySnackeBarError('Please enter a phone number'.tr);
return;
}
+ // Format Syrian phone number: remove leading 0 and add +963
String formattedPhoneNumber =
- _formatSyrianPhoneNumber(invitePhoneController.text);
- if (formattedPhoneNumber.length < 13) {
+ normalizeSyrianPhone(invitePhoneController.text);
+ if (formattedPhoneNumber.length != 12) {
mySnackeBarError('Please enter a correct phone'.tr);
return;
}
@@ -370,22 +400,32 @@ Download the Intaleq app now and enjoy your ride!
mySnackeBarError('Please enter a phone number'.tr);
return;
}
- String formattedPhoneNumber =
- _formatSyrianPhoneNumber(invitePhoneController.text);
- if (formattedPhoneNumber.length < 13) {
+
+ // Format Syrian phone number: remove leading 0 and add +963
+ String formattedPhoneNumber = invitePhoneController.text.trim();
+ if (formattedPhoneNumber.startsWith('0')) {
+ formattedPhoneNumber = formattedPhoneNumber.substring(1);
+ }
+ formattedPhoneNumber = '+963$formattedPhoneNumber';
+
+ if (formattedPhoneNumber.length < 12) {
+ // +963 + 9 digits = 12+
mySnackeBarError('Please enter a correct phone'.tr);
return;
}
- var response =
- await CRUD().post(link: AppLink.addInvitationPassenger, payload: {
- "driverId": box.read(BoxName.driverID),
- "inviterPassengerPhone": formattedPhoneNumber,
- });
+ var response = await CRUD().post(
+ link: AppLink.addInvitationPassenger,
+ payload: {
+ "driverId": box.read(BoxName.driverID),
+ "inviterPassengerPhone": formattedPhoneNumber,
+ },
+ );
if (response != 'failure') {
- var d = (response);
+ var d = response;
mySnackbarSuccess('Invite sent successfully'.tr);
+
String message = '${'*Intaleq APP CODE*'.tr}\n\n'
'${"Use this code in registration".tr}\n\n'
'${"To get a gift for both".tr}\n\n'
diff --git a/lib/controller/auth/captin/login_captin_controller.dart b/lib/controller/auth/captin/login_captin_controller.dart
index 3d65d9f..9af23a7 100755
--- a/lib/controller/auth/captin/login_captin_controller.dart
+++ b/lib/controller/auth/captin/login_captin_controller.dart
@@ -26,6 +26,7 @@ import '../../../views/auth/captin/otp_page.dart';
import '../../../views/auth/captin/otp_token_page.dart';
import '../../../views/auth/syria/pending_driver_page.dart';
import '../../firebase/firbase_messge.dart';
+import '../../firebase/local_notification.dart';
import '../../firebase/notification_service.dart';
import '../../functions/encrypt_decrypt.dart';
import '../../functions/package_info.dart';
@@ -177,11 +178,11 @@ class LoginDriverController extends GetxController {
Uri.parse(AppLink.loginFirstTimeDriver),
body: payload,
);
- // Log.print('response0: ${response0.body}');
- // Log.print('request: ${response0.request}');
+ Log.print('response0: ${response0.body}');
+ Log.print('request: ${response0.request}');
if (response0.statusCode == 200) {
final decodedResponse1 = jsonDecode(response0.body);
- // Log.print('decodedResponse1: ${decodedResponse1}');
+ Log.print('decodedResponse1: ${decodedResponse1}');
final jwt = decodedResponse1['jwt'];
box.write(BoxName.jwt, c(jwt));
@@ -253,6 +254,40 @@ class LoginDriverController extends GetxController {
.join('');
}
+ bool isInviteDriverFound = false;
+
+ Future updateInvitationCodeFromRegister() async {
+ var res = await CRUD().post(
+ link: AppLink.updateDriverInvitationDirectly,
+ payload: {
+ "inviterDriverPhone": box.read(BoxName.phoneDriver).toString(),
+ // "driverId": box.read(BoxName.driverID).toString(),
+ },
+ );
+ Log.print('invite: ${res}');
+
+ if (res['status'] != 'failure') {
+ isInviteDriverFound = true;
+ update();
+ // mySnackbarSuccess("Code approved".tr); // Localized success message
+ box.write(BoxName.isInstall, '1');
+ NotificationController().showNotification(
+ "Code approved".tr, "Code approved".tr, 'tone2', '');
+
+ NotificationService.sendNotification(
+ target: (res)['message'][0]['token'].toString(),
+ title: 'You have received a gift token!'.tr,
+ body: 'for '.tr + box.read(BoxName.phoneDriver).toString(),
+ isTopic: false, // Important: this is a token
+ tone: 'tone2',
+ driverList: [], category: 'You have received a gift token!',
+ );
+ } else {
+ // mySnackeBarError(
+ // "You dont have invitation code".tr); // Localized error message
+ }
+ }
+
loginWithGoogleCredential(String driverID, email) async {
isloading = true;
update();
@@ -263,7 +298,7 @@ class LoginDriverController extends GetxController {
// 'email': email ?? 'yet',
'id': driverID,
});
- // Log.print('res: ${res}');
+ Log.print('loginWithGoogleCredential: ${res}');
if (res == 'failure') {
await isPhoneVerified();
isloading = false; // <--- أضفت هذا أيضاً
@@ -314,6 +349,13 @@ class LoginDriverController extends GetxController {
} else if (int.parse(d['year'].toString()) < 2002) {
box.write(BoxName.carTypeOfDriver, 'Awfar Car');
}
+
+// add invitations
+ if (box.read(BoxName.isInstall) == null ||
+ box.read(BoxName.isInstall).toString() == '0') {
+ updateInvitationCodeFromRegister();
+ }
+
// updateAppTester(AppInformation.appName);
if (d['status'].toString() != 'yet') {
var token = await CRUD().get(
diff --git a/lib/controller/auth/captin/phone_helper_controller.dart b/lib/controller/auth/captin/phone_helper_controller.dart
index 357fff5..200cd96 100644
--- a/lib/controller/auth/captin/phone_helper_controller.dart
+++ b/lib/controller/auth/captin/phone_helper_controller.dart
@@ -18,14 +18,77 @@ class PhoneAuthHelper {
static final String _sendOtpUrl = '${_baseUrl}sendWhatsAppDriver.php';
static final String _verifyOtpUrl = '${_baseUrl}verifyOtp.php';
static final String _registerUrl = '${_baseUrl}register_driver.php';
+ static String formatSyrianPhone(String phone) {
+ // Remove spaces, symbols, +, -, ()
+ phone = phone.replaceAll(RegExp(r'[ \-\(\)\+]'), '').trim();
+
+ // Normalize 00963 → 963
+ if (phone.startsWith('00963')) {
+ phone = phone.replaceFirst('00963', '963');
+ }
+
+ // Normalize 0963 → 963
+ if (phone.startsWith('0963')) {
+ phone = phone.replaceFirst('0963', '963');
+ }
+ if (phone.startsWith('096309')) {
+ phone = phone.replaceFirst('096309', '963');
+ }
+
+ // NEW: Fix 96309xxxx → 9639xxxx
+ if (phone.startsWith('96309')) {
+ phone = '9639' + phone.substring(5); // remove the "0" after 963
+ }
+
+ // If starts with 9630 → correct to 9639
+ if (phone.startsWith('9630')) {
+ phone = '9639' + phone.substring(4);
+ }
+
+ // If already in correct format: 9639xxxxxxxx
+ if (phone.startsWith('9639') && phone.length == 12) {
+ return phone;
+ }
+
+ // If starts with 963 but missing the 9
+ if (phone.startsWith('963') && phone.length > 3) {
+ // Ensure it begins with 9639
+ if (!phone.startsWith('9639')) {
+ phone = '9639' + phone.substring(3);
+ }
+ return phone;
+ }
+
+ // If starts with 09xxxxxxxx → 9639xxxxxxxx
+ if (phone.startsWith('09')) {
+ return '963' + phone.substring(1);
+ }
+
+ // If 9xxxxxxxx (9 digits)
+ if (phone.startsWith('9') && phone.length == 9) {
+ return '963' + phone;
+ }
+
+ // If starts with incorrect 0xxxxxxx → assume Syrian and fix
+ if (phone.startsWith('0') && phone.length == 10) {
+ return '963' + phone.substring(1);
+ }
+
+ return phone;
+ }
/// Sends an OTP to the provided phone number.
static Future sendOtp(String phoneNumber) async {
try {
+ final fixedPhone = formatSyrianPhone(phoneNumber);
+ Log.print('fixedPhone: $fixedPhone');
+
final response = await CRUD().post(
link: _sendOtpUrl,
- payload: {'receiver': phoneNumber},
+ payload: {'receiver': fixedPhone},
);
+ Log.print('fixedPhone: ${fixedPhone}');
+
if (response != 'failure') {
final data = (response);
Log.print('data: ${data}');
@@ -49,10 +112,12 @@ class PhoneAuthHelper {
/// Verifies the OTP and logs the user in.
static Future verifyOtp(String phoneNumber) async {
try {
+ final fixedPhone = formatSyrianPhone(phoneNumber);
+ Log.print('fixedPhone: $fixedPhone');
final response = await CRUD().post(
link: _verifyOtpUrl,
payload: {
- 'phone_number': phoneNumber,
+ 'phone_number': fixedPhone,
},
);
@@ -80,7 +145,7 @@ class PhoneAuthHelper {
// ✅ رقم الهاتف تم التحقق منه لكن السائق غير مسجل
// mySnackbarSuccess('Phone verified. Please complete registration.');
// Get.offAll(() => SyrianCardAI());
- Get.offAll(() => RegistrationView());
+ Get.to(() => RegistrationView());
}
} else {
mySnackeBarError(data['message'] ?? 'Verification failed.');
diff --git a/lib/controller/auth/captin/register_captin_controller.dart b/lib/controller/auth/captin/register_captin_controller.dart
index 53763c3..eeac62c 100755
--- a/lib/controller/auth/captin/register_captin_controller.dart
+++ b/lib/controller/auth/captin/register_captin_controller.dart
@@ -280,7 +280,7 @@ class RegisterCaptainController extends GetxController {
// box.read(BoxName.emailDriver).toString(),
// );
// Get.offAll(() => SyrianCardAI());
- Get.offAll(() => RegistrationView());
+ Get.to(() => RegistrationView());
// } else {
// Get.snackbar('title', 'message');
// }
diff --git a/lib/controller/auth/syria/registration_controller.dart b/lib/controller/auth/syria/registration_controller.dart
index fb67c8e..706e6da 100644
--- a/lib/controller/auth/syria/registration_controller.dart
+++ b/lib/controller/auth/syria/registration_controller.dart
@@ -58,6 +58,7 @@ class RegistrationController extends GetxController {
final firstNameController = TextEditingController();
final lastNameController = TextEditingController();
final nationalIdController = TextEditingController();
+ final bithdateController = TextEditingController();
final phoneController = TextEditingController(); // You can pre-fill this
final driverLicenseExpiryController = TextEditingController();
DateTime? driverLicenseExpiryDate;
@@ -101,14 +102,15 @@ class RegistrationController extends GetxController {
isValid = driverInfoFormKey.currentState!.validate();
if (isValid) {
// Optional: Check if license is expired
- if (driverLicenseExpiryDate != null &&
- driverLicenseExpiryDate!.isBefore(DateTime.now())) {
- Get.snackbar('Expired License', 'Your driver’s license has expired.',
- snackPosition: SnackPosition.BOTTOM,
- backgroundColor: Colors.red,
- colorText: Colors.white);
- return; // Stop progression
- }
+ // if (driverLicenseExpiryDate != null &&
+ // driverLicenseExpiryDate!.isBefore(DateTime.now())) {
+ // Get.snackbar('Expired License', 'Your driver’s license has expired.'.tr
+ // ,
+ // snackPosition: SnackPosition.BOTTOM,
+ // backgroundColor: Colors.red,
+ // colorText: Colors.white);
+ // return; // Stop progression
+ // }
}
} else if (currentPage.value == 1) {
// Validate Step 2
@@ -495,6 +497,7 @@ class RegistrationController extends GetxController {
_addField(fields, 'last_name', lastNameController.text);
_addField(fields, 'phone', box.read(BoxName.phoneDriver) ?? '');
_addField(fields, 'national_number', nationalIdController.text);
+ _addField(fields, 'birthdate', bithdateController.text);
_addField(fields, 'expiry_date', driverLicenseExpiryController.text);
_addField(
fields, 'password', 'generate_your_password_here'); // عدّل حسب منطقك
diff --git a/lib/controller/firebase/firbase_messge.dart b/lib/controller/firebase/firbase_messge.dart
index b4c948a..4a42660 100755
--- a/lib/controller/firebase/firbase_messge.dart
+++ b/lib/controller/firebase/firbase_messge.dart
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:io';
import 'package:sefer_driver/controller/home/captin/home_captain_controller.dart';
+import 'package:sefer_driver/views/home/Captin/orderCaptin/order_speed_request.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
@@ -117,7 +118,7 @@ class FirebaseMessagesController extends GetxController {
driverToken = myList[14].toString();
Get.put(HomeCaptainController()).changeRideId();
update();
- Get.to(() => OrderRequestPage(), arguments: {
+ Get.to(() => OrderSpeedRequest(), arguments: {
'myListString': myListString,
'DriverList': myList,
'body': body
diff --git a/lib/controller/functions/gemeni.dart b/lib/controller/functions/gemeni.dart
index af1e987..f070d29 100755
--- a/lib/controller/functions/gemeni.dart
+++ b/lib/controller/functions/gemeni.dart
@@ -114,7 +114,7 @@ class AI extends GetxController {
// 'tone2', // Type of notification
// );
NotificationService.sendNotification(
- target: jsonDecode(res)['message'][0]['token'].toString(),
+ target: (res)['message'][0]['token'].toString(),
title: 'You have received a gift token!'.tr,
body: 'for '.tr + box.read(BoxName.phoneDriver).toString(),
isTopic: false, // Important: this is a token
diff --git a/lib/controller/functions/launch.dart b/lib/controller/functions/launch.dart
index 26a7026..32b588e 100755
--- a/lib/controller/functions/launch.dart
+++ b/lib/controller/functions/launch.dart
@@ -8,11 +8,32 @@ void showInBrowser(String url) async {
}
Future makePhoneCall(String phoneNumber) async {
+ // 1. تنظيف الرقم (إزالة المسافات والفواصل)
+ String formattedNumber = phoneNumber.replaceAll(RegExp(r'\s+'), '');
+
+ // 2. التحقق من طول الرقم لتحديد طريقة التنسيق
+ if (formattedNumber.length > 6) {
+ // --- التعديل المطلوب ---
+ if (formattedNumber.startsWith('09')) {
+ // إذا كان يبدأ بـ 09 (رقم موبايل سوري محلي)
+ // نحذف أول خانة (الصفر) ونضيف +963
+ formattedNumber = '+963${formattedNumber.substring(1)}';
+ } else if (!formattedNumber.startsWith('+')) {
+ // إذا لم يكن يبدأ بـ + (ولم يكن يبدأ بـ 09)، نضيف + في البداية
+ // هذا للحفاظ على منطقك القديم للأرقام الدولية الأخرى
+ formattedNumber = '+$formattedNumber';
+ }
+ }
+
+ // 3. التنفيذ (Launch)
final Uri launchUri = Uri(
scheme: 'tel',
- path: phoneNumber,
+ path: formattedNumber,
);
- await launchUrl(launchUri);
+
+ if (await canLaunchUrl(launchUri)) {
+ await launchUrl(launchUri);
+ }
}
void launchCommunication(
diff --git a/lib/controller/functions/log_out.dart b/lib/controller/functions/log_out.dart
index ca286a2..7b3634c 100755
--- a/lib/controller/functions/log_out.dart
+++ b/lib/controller/functions/log_out.dart
@@ -1,5 +1,3 @@
-import 'dart:io';
-
import 'package:sefer_driver/views/home/on_boarding_page.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:flutter/material.dart';
@@ -9,12 +7,10 @@ import 'package:sefer_driver/constant/colors.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
-import 'package:sefer_driver/onbording_page.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:sefer_driver/views/widgets/my_textField.dart';
import '../../constant/style.dart';
-import 'encrypt_decrypt.dart';
class LogOutController extends GetxController {
TextEditingController checkTxtController = TextEditingController();
diff --git a/lib/controller/functions/package_info.dart b/lib/controller/functions/package_info.dart
index 6c313da..24a708b 100755
--- a/lib/controller/functions/package_info.dart
+++ b/lib/controller/functions/package_info.dart
@@ -48,7 +48,7 @@ Future getPackageInfo() async {
void showUpdateDialog(BuildContext context) {
final String storeUrl = Platform.isAndroid
? 'https://play.google.com/store/apps/details?id=com.intaleq_driver'
- : 'https://apps.apple.com/ae/app/intaleq-driver/id6502189302';
+ : 'https://apps.apple.com/jo/app/intaleq-driver/id6482995159';
showGeneralDialog(
context: context,
diff --git a/lib/controller/home/captin/behavior_controller.dart b/lib/controller/home/captin/behavior_controller.dart
index e5cf6a7..1c51f4b 100644
--- a/lib/controller/home/captin/behavior_controller.dart
+++ b/lib/controller/home/captin/behavior_controller.dart
@@ -52,31 +52,58 @@ class DriverBehaviorController extends GetxController {
double totalSpeed = 0;
int hardBrakes = 0;
double totalDistance = 0;
+
+ // متغيرات للمقارنة مع النقطة السابقة
double? prevLat, prevLng;
+ DateTime? prevTime;
+
+ // ترتيب البيانات حسب الوقت لضمان دقة الحساب (اختياري لكن مفضل)
+ // data.sort((a, b) => a['created_at'].compareTo(b['created_at']));
for (var item in data) {
- double speed = item['speed'] ?? 0;
- double lat = item['lat'] ?? 0;
- double lng = item['lng'] ?? 0;
- double acc = item['acceleration'] ?? 0;
+ // 1. قراءة البيانات بالأسماء الصحيحة من الجدول
+ double lat = item['latitude'] ?? item['lat'] ?? 0.0;
+ double lng = item['longitude'] ?? item['lng'] ?? 0.0;
+ double acc = item['acceleration'] ?? 0.0;
- if (speed > maxSpeed) maxSpeed = speed;
- totalSpeed += speed;
+ // قراءة الوقت لحساب السرعة
+ DateTime currentTime =
+ DateTime.tryParse(item['created_at'].toString()) ?? DateTime.now();
- // ✅ Hard brake threshold
+ double currentSpeed = 0;
+
+ // 2. حساب السرعة والمسافة إذا وجدت نقطة سابقة
+ if (prevLat != null && prevLng != null && prevTime != null) {
+ double distKm = _calculateDistance(prevLat, prevLng, lat, lng);
+ int timeDiffSeconds = currentTime.difference(prevTime).inSeconds;
+
+ if (timeDiffSeconds > 0) {
+ // السرعة (كم/س) = (المسافة بالكيلومتر * 3600) / الزمن بالثواني
+ currentSpeed = (distKm * 3600) / timeDiffSeconds;
+ }
+
+ totalDistance += distKm;
+ }
+
+ // تحديث القيم الإحصائية
+ if (currentSpeed > maxSpeed) maxSpeed = currentSpeed;
+ totalSpeed += currentSpeed;
+
+ // حساب الفرملة القوية (يعتمد على التسارع المحفوظ مسبقاً)
if (acc.abs() > 3.0) hardBrakes++;
- // ✅ Distance between points
- if (prevLat != null && prevLng != null) {
- totalDistance += _calculateDistance(prevLat, prevLng, lat, lng);
- }
+ // حفظ النقطة الحالية لتكون هي "السابقة" في الدورة التالية
prevLat = lat;
prevLng = lng;
+ prevTime = currentTime;
}
- double avgSpeed = totalSpeed / data.length;
+ // تجنب القسمة على صفر
+ double avgSpeed = (data.length > 1) ? totalSpeed / (data.length - 1) : 0;
+
+ // حساب تقييم السلوك
double behaviorScore = 100 - (hardBrakes * 5) - ((maxSpeed > 100) ? 10 : 0);
- behaviorScore = behaviorScore.clamp(0, 100);
+ behaviorScore = behaviorScore.clamp(0.0, 100.0);
return {
'max_speed': maxSpeed,
diff --git a/lib/controller/home/captin/duration_controller .dart b/lib/controller/home/captin/duration_controller .dart
index 2807572..3945a41 100755
--- a/lib/controller/home/captin/duration_controller .dart
+++ b/lib/controller/home/captin/duration_controller .dart
@@ -35,7 +35,7 @@ class DurationController extends GetxController {
getStaticDriver() async {
isLoading = true;
update();
- var res = await CRUD().getWallet(
+ var res = await CRUD().get(
link: AppLink.driverStatistic,
payload: {'driverID': box.read(BoxName.driverID)});
if (res == 'failure') {
diff --git a/lib/controller/home/captin/home_captain_controller.dart b/lib/controller/home/captin/home_captain_controller.dart
index 89dff0b..ca7e284 100755
--- a/lib/controller/home/captin/home_captain_controller.dart
+++ b/lib/controller/home/captin/home_captain_controller.dart
@@ -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();
+
+ // --- 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().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>(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().getLocation();
+
+ var loc = Get.find().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