This commit is contained in:
Hamza-Ayed
2024-08-27 10:49:43 +03:00
parent 2bc71355c3
commit d23020188e
48 changed files with 1872 additions and 432 deletions

View File

@@ -29,9 +29,9 @@ class CRUD {
},
);
// if (response.statusCode == 200) {
// Log.print('response: ${response.request}');
// Log.print('response: ${response.body}');
// Log.print('response: ${payload}');
Log.print('response: ${response.request}');
Log.print('response: ${response.body}');
Log.print('response: ${payload}');
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return response.body;
@@ -101,7 +101,9 @@ class CRUD {
var extractedString =
await arabicTextExtractByVisionAndAI(imagePath: imagePath);
var json = jsonDecode(extractedString);
var textValues = extractTextFromLines(json);
Log.print('textValues: ${textValues}');
// await Get.put(AI()).geminiAiExtraction(prompt, textValues);
await Get.put(AI()).anthropicAI(textValues, prompt, imagePath);
}
@@ -145,6 +147,8 @@ class CRUD {
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
// Log.print(
// 'response.stream.bytesToString(): ${await response.stream.bytesToString()}');
return await response.stream.bytesToString();
} else {}
}
@@ -227,6 +231,8 @@ class CRUD {
);
Log.print('response: ${response.request}');
Log.print('response: ${response.body}');
Log.print('response: ${response.statusCode}');
Log.print('response: ${response.reasonPhrase}');
Log.print('response: ${payload}');
var jsonData = jsonDecode(response.body);
if (response.statusCode == 200) {

View File

@@ -250,6 +250,39 @@ class AI extends GetxController {
}
}
String extractDOB(String nationalNumber) {
if (nationalNumber.length != 14) {
throw ArgumentError('National number must be 14 digits long.');
}
// Extract the first digit to determine the century
String firstDigit = nationalNumber[0];
// Extract year, month, and day parts
String yearPart = nationalNumber.substring(1, 3);
String monthPart = nationalNumber.substring(3, 5);
String dayPart = nationalNumber.substring(5, 7);
// Determine the year based on the first digit
int yearPrefix;
if (firstDigit == '2') {
yearPrefix = 1900;
} else if (firstDigit == '3') {
yearPrefix = 2000;
} else {
throw ArgumentError('Invalid first digit in national number.');
}
// Construct the full year
int year = yearPrefix + int.parse(yearPart);
// Format the date as YYYY-MM-DD
String dob =
'$year-${monthPart.padLeft(2, '0')}-${dayPart.padLeft(2, '0')}';
return dob;
}
Future<void> addDriverEgypt() async {
isLoading = true;
update();
@@ -295,7 +328,8 @@ class AI extends GetxController {
'religion':
responseIdEgyptBack['religion']?.toString() ?? 'Not specified',
'status': 'yet',
'birthdate': responseIdEgyptFront['dob']?.toString() ?? 'Not specified',
'birthdate': extractDOB(
responseIdEgyptDriverLicense['national_number'].toString()),
'maritalStatus':
responseIdEgyptBack['maritalStatus']?.toString() ?? 'Not specified',
'site': responseIdEgyptDriverLicense['address']?.toString() ??
@@ -321,6 +355,12 @@ class AI extends GetxController {
if (status1['status'] == 'success') {
isDriverSaved = true;
// CRUD().post(
// link: '${AppLink.seferGizaServer}/auth/captin/register.php',
// payload: payload);
// CRUD().post(
// link: '${AppLink.seferAlexandriaServer}/auth/captin/register.php',
// payload: payload);
Get.snackbar('Success', 'Driver data saved successfully',
backgroundColor: AppColor.greenColor);
} else {
@@ -376,6 +416,55 @@ class AI extends GetxController {
isCarSaved = true;
Get.snackbar('Success', 'message',
backgroundColor: AppColor.greenColor);
// CRUD().post(
// link:
// '${AppLink.seferAlexandriaServer}/ride/RegisrationCar/add.php',
// payload: {
// 'driverID': box.read(BoxName.driverID),
// 'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
// 'car_plate':
// responseIdCardDriverEgyptFront['car_plate'].toString(),
// 'make': responseIdCardDriverEgyptBack['make'].toString(),
// 'model': responseIdCardDriverEgyptBack['model'],
// 'year': responseIdCardDriverEgyptBack['year'].toString(),
// 'expiration_date':
// responseIdCardDriverEgyptFront['LicenseExpirationDate']
// .toString(),
// 'color': responseIdCardDriverEgyptBack['color'],
// 'owner': responseIdCardDriverEgyptFront['owner'],
// 'color_hex':
// responseIdCardDriverEgyptBack['color_hex'].toString(),
// 'address': responseIdCardDriverEgyptFront['address'].toString(),
// 'displacement':
// responseIdCardDriverEgyptBack['engine'].toString(),
// 'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
// 'registration_date':
// '${responseIdCardDriverEgyptBack['inspection_date']}',
// });
// CRUD().post(
// link: '${AppLink.seferGizaServer}/ride/RegisrationCar/add.php',
// payload: {
// 'driverID': box.read(BoxName.driverID),
// 'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
// 'car_plate':
// responseIdCardDriverEgyptFront['car_plate'].toString(),
// 'make': responseIdCardDriverEgyptBack['make'].toString(),
// 'model': responseIdCardDriverEgyptBack['model'],
// 'year': responseIdCardDriverEgyptBack['year'].toString(),
// 'expiration_date':
// responseIdCardDriverEgyptFront['LicenseExpirationDate']
// .toString(),
// 'color': responseIdCardDriverEgyptBack['color'],
// 'owner': responseIdCardDriverEgyptFront['owner'],
// 'color_hex':
// responseIdCardDriverEgyptBack['color_hex'].toString(),
// 'address': responseIdCardDriverEgyptFront['address'].toString(),
// 'displacement':
// responseIdCardDriverEgyptBack['engine'].toString(),
// 'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
// 'registration_date':
// '${responseIdCardDriverEgyptBack['inspection_date']}',
// });
}
} catch (e) {}
}

View File

@@ -26,9 +26,9 @@ class LocationBackgroundController extends GetxController {
Future<void> configureBackgroundLocation() async {
await BackgroundLocation.setAndroidNotification(
title: "Background Location",
message: "Tracking location...",
icon: "@mipmap/launcher_icon",
title: 'Location Tracking Active'.tr,
message: 'Your location is being tracked in the background.'.tr,
icon: '@mipmap/launcher_icon',
);
// Set the location update interval to 5 seconds

View File

@@ -10,6 +10,8 @@ import 'package:SEFER/controller/functions/crud.dart';
import 'package:SEFER/controller/home/payment/captain_wallet_controller.dart';
import 'package:SEFER/main.dart';
import '../../print.dart';
// LocationController.dart
class LocationController extends GetxController {
LocationData? _currentLocation;
@@ -40,6 +42,36 @@ class LocationController extends GetxController {
totalPoints = Get.put(CaptainWalletController()).totalPoints.toString();
// isActive = Get.put(HomeCaptainController()).isActive;
} // Function to determine which area the coordinates belong to
String getLocationArea(double latitude, double longitude) {
// Giza Boundary Check
if (latitude >= 29.904975 &&
latitude <= 30.143372 &&
longitude >= 30.787030 &&
longitude <= 31.238843) {
// box.write(BoxName.serverChosen, AppLink.seferGizaServer);
return 'Giza';
}
// Cairo Boundary Check
else if (latitude >= 29.918901 &&
latitude <= 30.198857 &&
longitude >= 31.215009 &&
longitude <= 31.532186) {
// box.write(BoxName.serverChosen, AppLink.seferCairoServer);
return 'Cairo';
}
// Alexandria Boundary Check
else if (latitude >= 30.396286 &&
latitude <= 31.654458 &&
longitude >= 29.041139 &&
longitude <= 32.626259) {
// box.write(BoxName.serverChosen, AppLink.seferAlexandriaServer);
return 'Alexandria';
}
// Return 'Unknown' if outside defined areas
return 'Unknown';
}
Future<void> startLocationUpdates() async {
@@ -53,53 +85,69 @@ class LocationController extends GetxController {
if (isActive) {
if (double.parse(totalPoints) > -3000) {
await getLocation();
String endpoint;
// 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()
});
// 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,
// )));
switch (
getLocationArea(myLocation.latitude, myLocation.longitude)) {
case 'Cairo':
endpoint = AppLink.addCarsLocationCairoEndpoint;
break;
case 'Giza':
endpoint = AppLink.addCarsLocationGizaEndpoint;
break;
case 'Alexandria':
endpoint = AppLink.addCarsLocationAlexandriaEndpoint;
break;
default:
print('Location outside Cairo, Giza, or Alexandria');
endpoint = AppLink.addCarsLocationByPassenger;
return;
}
if (box.read(BoxName.driverID) != null) {
await CRUD().post(link: endpoint, 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.0'
: totalDistance < 1
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation).toString()
});
// 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,
// )));
}
Get.find<HomeCaptainController>()
.mapHomeCaptainController!
.animateCamera(CameraUpdate.newLatLng(LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
)));
// if (Get.find<HomeCaptainController>().rideId == '0') {
// await sql.insertData({
// 'driver_id': box.read(BoxName.driverID),
// 'latitude': myLocation.latitude.toString(),
// 'longitude': myLocation.longitude.toString(),
// 'created_at': DateTime.now().toString(),
// }, TableName.carLocations);
// } else {
// await sql.insertData({
// 'order_id': Get.find<MapDriverController>().rideId,
// 'created_at': DateTime.now().toString(),
// 'lat': myLocation.latitude.toString(),
// 'lng': myLocation.longitude.toString(),
// }, TableName.rideLocation);
// }
}
Get.find<HomeCaptainController>()
.mapHomeCaptainController!
.animateCamera(CameraUpdate.newLatLng(LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
)));
// if (Get.find<HomeCaptainController>().rideId == '0') {
// await sql.insertData({
// 'driver_id': box.read(BoxName.driverID),
// 'latitude': myLocation.latitude.toString(),
// 'longitude': myLocation.longitude.toString(),
// 'created_at': DateTime.now().toString(),
// }, TableName.carLocations);
// } else {
// await sql.insertData({
// 'order_id': Get.find<MapDriverController>().rideId,
// 'created_at': DateTime.now().toString(),
// 'lat': myLocation.latitude.toString(),
// 'lng': myLocation.longitude.toString(),
// }, TableName.rideLocation);
// }
// }
//
}
@@ -151,10 +199,13 @@ class LocationController extends GetxController {
(_locationData.latitude != null && _locationData.longitude != null
? LatLng(_locationData.latitude!, _locationData.longitude!)
: null)!;
getLocationArea(_locationData.latitude!, _locationData.longitude!);
speed = _locationData.speed!;
heading = _locationData.heading!;
// Calculate the distance between the current location and the previous location
if (Get.find<HomeCaptainController>().rideId == 'rideId') {
Log.print(
'Get.find<HomeCaptainController>().rideId: ${Get.find<HomeCaptainController>().rideId}');
if (previousTime > 0) {
double distance = calculateDistanceInKmPerHour(
previousTime, _locationData.time, speed);

View File

@@ -64,6 +64,12 @@ void showUpdateDialog(BuildContext context) {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text('Cancel'.tr),
onPressed: () async {
Navigator.of(context).pop();
},
),
],
);
},

View File

@@ -14,6 +14,7 @@ import 'package:path_provider/path_provider.dart' as path_provider;
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../main.dart';
import '../../print.dart';
class ImageController extends GetxController {
File? myImage;
@@ -138,6 +139,7 @@ class ImageController extends GetxController {
File compressedImage = await compressImage(processedImage);
print('link =$link');
Log.print('link: ${link}');
await uploadImage(
compressedImage,
@@ -238,7 +240,7 @@ class ImageController extends GetxController {
uploadImage(File file, Map data, String link) async {
var request = http.MultipartRequest(
'POST',
Uri.parse(link), //'https://ride.mobile-app.store/uploadImage1.php'
Uri.parse(link),
);
var length = await file.length();
@@ -268,6 +270,7 @@ class ImageController extends GetxController {
var myrequest = await request.send();
var res = await http.Response.fromStream(myrequest);
if (res.statusCode == 200) {
Log.print('jsonDecode(res.body): ${jsonDecode(res.body)}');
return jsonDecode(res.body);
} else {
throw Exception(

View File

@@ -0,0 +1,15 @@
import 'package:get/get.dart';
import '../../constant/box_name.dart';
import '../../main.dart';
class HomePageController extends GetxController {
late bool isVibrate = box.read(BoxName.isvibrate) ?? true;
void changeVibrateOption(bool value) {
isVibrate = box.read(BoxName.isvibrate) ?? true;
isVibrate = value;
box.write(BoxName.isvibrate, value);
update();
}
}