25-12-1/1

This commit is contained in:
Hamza-Ayed
2025-12-01 07:53:52 +03:00
parent 1a0bf1ee32
commit 11dfe94bbb
49 changed files with 19013 additions and 15915 deletions

View File

@@ -17,9 +17,6 @@ import 'encrypt_decrypt.dart';
import 'upload_image.dart';
import 'dart:io';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'network/connection_check.dart';
import 'network/net_guard.dart';
class CRUD {
@@ -364,29 +361,29 @@ class CRUD {
}
}
Future<dynamic> getTokenParent({
required String link,
Map<String, dynamic>? payload,
}) async {
// Uses Basic Auth, so it's a separate implementation.
var url = Uri.parse(
link,
);
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
},
);
if (response.statusCode == 200) {
return jsonDecode(response.body);
}
// Consider adding error handling here.
return null;
}
// Future<dynamic> getTokenParent({
// required String link,
// Map<String, dynamic>? payload,
// }) async {
// // Uses Basic Auth, so it's a separate implementation.
// var url = Uri.parse(
// link,
// );
// var response = await http.post(
// url,
// body: payload,
// headers: {
// "Content-Type": "application/x-www-form-urlencoded",
// 'Authorization':
// 'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
// },
// );
// if (response.statusCode == 200) {
// return jsonDecode(response.body);
// }
// // Consider adding error handling here.
// return null;
// }
Future sendWhatsAppAuth(String to, String token) async {
var res = await CRUD()

View File

@@ -8,11 +8,32 @@ void showInBrowser(String url) async {
}
Future<void> 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(

View File

@@ -1,148 +1,148 @@
import 'dart:async';
// import 'dart:async';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
import 'package:Intaleq/constant/box_name.dart';
import 'package:Intaleq/constant/links.dart';
import 'package:Intaleq/controller/functions/crud.dart';
import 'package:Intaleq/controller/home/payment/captain_wallet_controller.dart';
import 'package:Intaleq/main.dart';
// import 'package:get/get.dart';
// import 'package:google_maps_flutter/google_maps_flutter.dart';
// import 'package:location/location.dart';
// import 'package:Intaleq/constant/box_name.dart';
// import 'package:Intaleq/constant/links.dart';
// import 'package:Intaleq/controller/functions/crud.dart';
// import 'package:Intaleq/controller/home/payment/captain_wallet_controller.dart';
// import 'package:Intaleq/main.dart';
// LocationController.dart
class LocationController extends GetxController {
LocationData? _currentLocation;
late Location location;
bool isLoading = false;
late double heading = 0;
late double accuracy = 0;
late double previousTime = 0;
late double latitude;
late double totalDistance = 0;
late double longitude;
late DateTime time;
late double speed = 0;
late double speedAccuracy = 0;
late double headingAccuracy = 0;
bool isActive = false;
late LatLng myLocation;
String totalPoints = '0';
LocationData? get currentLocation => _currentLocation;
Timer? _locationTimer;
// // LocationController.dart
// class LocationController extends GetxController {
// LocationData? _currentLocation;
// late Location location;
// bool isLoading = false;
// late double heading = 0;
// late double accuracy = 0;
// late double previousTime = 0;
// late double latitude;
// late double totalDistance = 0;
// late double longitude;
// late DateTime time;
// late double speed = 0;
// late double speedAccuracy = 0;
// late double headingAccuracy = 0;
// bool isActive = false;
// late LatLng myLocation;
// String totalPoints = '0';
// LocationData? get currentLocation => _currentLocation;
// Timer? _locationTimer;
@override
void onInit() async {
super.onInit();
location = Location();
getLocation();
// startLocationUpdates();
// @override
// void onInit() async {
// super.onInit();
// location = Location();
// getLocation();
// // startLocationUpdates();
totalPoints = Get.put(CaptainWalletController()).totalPoints;
}
// totalPoints = Get.put(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;
// 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) > -300) {
await getLocation();
// // if (isActive) {
// if (double.parse(totalPoints) > -300) {
// await getLocation();
// if (box.read(BoxName.driverID) != null) {
await CRUD()
.post(link: AppLink.addCarsLocationByPassenger, 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
? '0'
: totalDistance < 1
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation).toString()
});
}
// // if (box.read(BoxName.driverID) != null) {
// await CRUD()
// .post(link: AppLink.addCarsLocationByPassenger, 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
// ? '0'
// : totalDistance < 1
// ? totalDistance.toStringAsFixed(3)
// : totalDistance.toStringAsFixed(1),
// 'status': box.read(BoxName.statusDriverLocation).toString()
// });
// }
// }
} catch (e) {
// Handle the error gracefully
}
});
}
}
// // }
// } catch (e) {
// // Handle the error gracefully
// }
// });
// }
// }
void stopLocationUpdates() {
_locationTimer?.cancel();
}
// void stopLocationUpdates() {
// _locationTimer?.cancel();
// }
Future<void> getLocation() async {
// isLoading = true;
// update();
bool serviceEnabled;
PermissionStatus permissionGranted;
// Future<void> getLocation() async {
// // isLoading = true;
// // update();
// bool serviceEnabled;
// PermissionStatus permissionGranted;
// Check if location services are enabled
serviceEnabled = await location.serviceEnabled();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
if (!serviceEnabled) {
// Location services are still not enabled, handle the error
return;
}
}
// // Check if location services are enabled
// serviceEnabled = await location.serviceEnabled();
// if (!serviceEnabled) {
// serviceEnabled = await location.requestService();
// if (!serviceEnabled) {
// // Location services are still not enabled, handle the error
// return;
// }
// }
// Check if the app has permission to access location
permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted != PermissionStatus.granted) {
// Location permission is still not granted, handle the error
return;
}
}
// // Check if the app has permission to access location
// permissionGranted = await location.hasPermission();
// if (permissionGranted == PermissionStatus.denied) {
// permissionGranted = await location.requestPermission();
// if (permissionGranted != PermissionStatus.granted) {
// // Location permission is still not granted, handle the error
// return;
// }
// }
// Configure location accuracy
// LocationAccuracy desiredAccuracy = LocationAccuracy.high;
// // Configure location accuracy
// // LocationAccuracy desiredAccuracy = LocationAccuracy.high;
// Get the current location
LocationData _locationData = await location.getLocation();
myLocation =
(_locationData.latitude != null && _locationData.longitude != null
? LatLng(_locationData.latitude!, _locationData.longitude!)
: null)!;
speed = _locationData.speed!;
heading = _locationData.heading!;
// Calculate the distance between the current location and the previous location
// if (Get.find<HomeCaptainController>().rideId == 'rideId') {
// if (previousTime > 0) {
// double distance = calculateDistanceInKmPerHour(
// previousTime, _locationData.time, speed);
// totalDistance += distance;
// }
// // Get the current location
// LocationData _locationData = await location.getLocation();
// myLocation =
// (_locationData.latitude != null && _locationData.longitude != null
// ? LatLng(_locationData.latitude!, _locationData.longitude!)
// : null)!;
// speed = _locationData.speed!;
// heading = _locationData.heading!;
// // Calculate the distance between the current location and the previous location
// // if (Get.find<HomeCaptainController>().rideId == 'rideId') {
// // if (previousTime > 0) {
// // double distance = calculateDistanceInKmPerHour(
// // previousTime, _locationData.time, speed);
// // totalDistance += distance;
// // }
// previousTime = _locationData.time!;
// }
// Print location details
// isLoading = false;
update();
}
// // previousTime = _locationData.time!;
// // }
// // Print location details
// // isLoading = false;
// update();
// }
double calculateDistanceInKmPerHour(
double? startTime, double? endTime, double speedInMetersPerSecond) {
// Calculate the time difference in hours
double timeDifferenceInHours = (endTime! - startTime!) / 1000 / 3600;
// double calculateDistanceInKmPerHour(
// double? startTime, double? endTime, double speedInMetersPerSecond) {
// // Calculate the time difference in hours
// double timeDifferenceInHours = (endTime! - startTime!) / 1000 / 3600;
// Convert speed to kilometers per hour
double speedInKmPerHour = speedInMetersPerSecond * 3.6;
// // Convert speed to kilometers per hour
// double speedInKmPerHour = speedInMetersPerSecond * 3.6;
// Calculate the distance in kilometers
double distanceInKilometers = speedInKmPerHour * timeDifferenceInHours;
// // Calculate the distance in kilometers
// double distanceInKilometers = speedInKmPerHour * timeDifferenceInHours;
return distanceInKilometers;
}
}
// return distanceInKilometers;
// }
// }