This commit is contained in:
Hamza-Ayed
2024-01-18 00:49:00 +03:00
parent 358bb904ab
commit 7af7e71b30
17 changed files with 1028 additions and 269 deletions

View File

@@ -12,10 +12,14 @@ import '../../constant/colors.dart';
class ContentController extends GetxController {
final picker = ImagePicker();
Map<String, dynamic> responseMap = {};
Map<String, dynamic> responseCarLicenseMap = {};
Map<String, dynamic> responseBackCarLicenseMap = {};
Map<String, dynamic> responseIdCardeMap = {};
bool isloading = false;
var image;
CroppedFile? croppedFile;
DateTime now = DateTime.now();
Future<void> pickImage() async {
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
@@ -153,6 +157,294 @@ class ContentController extends GetxController {
}
}
Future<void> generateDriverLicenseJordanContent() async {
await pickImage();
isloading = true;
update();
if (image != null) {
final imageBytes = await image.readAsBytes();
final imageData = base64Encode(imageBytes);
var requestBody = jsonEncode({
'contents': [
{
'parts': [
{
'inlineData': {
'mimeType': 'image/jpeg',
'data': imageData,
},
},
{
'text':
'write json for all data as first name ,last name,dob,id ,expiration date,issued date asdress class type,age in years ,output json type in arabic value and stay engish key and make date format like YYYY-MM-DD , for name please extract name in arabic in Name in json plus first_name ',
},
],
},
],
'generationConfig': {
'temperature': 0.4,
'topK': 32,
'topP': 1,
'maxOutputTokens': 4096,
'stopSequences': [],
},
'safetySettings': [
{
'category': 'HARM_CATEGORY_HARASSMENT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_HATE_SPEECH',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
],
});
print(requestBody);
final response = await http.post(
Uri.parse(
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
headers: {'Content-Type': 'application/json'},
body: requestBody,
);
isloading = false;
update();
if (response.statusCode == 200) {
var responseData = jsonDecode(response.body);
// Process the responseData as needed
// print(responseData);
var result =
responseData['candidates'][0]['content']['parts'][0]['text'];
// print(jsonEncode(result));
// print((result));
// print(result['dob']);
RegExp regex = RegExp(r"```json([^`]*)```");
String? jsonString =
regex.firstMatch(responseData.toString())?.group(1)?.trim();
if (jsonString != null) {
// Convert the JSON object to a String
jsonString = jsonEncode(json.decode(jsonString));
responseMap = jsonDecode(jsonString);
print(jsonString);
print(responseMap);
print(responseMap['dob']);
} else {
print("JSON string not found");
}
// Rest of your code...
} else {
print('Request failed with status: ${response.statusCode}');
print('Request failed with status: ${response.body}');
}
} else {
print('No image selected');
}
}
Future<void> generateCarLicenseJordanContent() async {
await pickImage();
isloading = true;
update();
if (image != null) {
final imageBytes = await image.readAsBytes();
final imageData = base64Encode(imageBytes);
var requestBody = jsonEncode({
'contents': [
{
'parts': [
{
'inlineData': {
'mimeType': 'image/jpeg',
'data': imageData,
},
},
{
'text':
'write json output of this car license in jordan json contain name , address , car kind ,car color , car year , car plate ,registration adjective , using ,expire date of license and make date format like YYYY-MM-DD .dont add data else this image',
},
],
},
],
'generationConfig': {
'temperature': 0.4,
'topK': 32,
'topP': 1,
'maxOutputTokens': 4096,
'stopSequences': [],
},
'safetySettings': [
{
'category': 'HARM_CATEGORY_HARASSMENT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_HATE_SPEECH',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
],
});
print(requestBody);
final response = await http.post(
Uri.parse(
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
headers: {'Content-Type': 'application/json'},
body: requestBody,
);
isloading = false;
update();
if (response.statusCode == 200) {
var responseData = jsonDecode(response.body);
// Process the responseData as needed
// print(responseData);
var result =
responseData['candidates'][0]['content']['parts'][0]['text'];
// print(jsonEncode(result));
// print((result));
// print(result['dob']);
RegExp regex = RegExp(r"```json([^`]*)```");
String? jsonString =
regex.firstMatch(responseData.toString())?.group(1)?.trim();
if (jsonString != null) {
// Convert the JSON object to a String
jsonString = jsonEncode(json.decode(jsonString));
responseCarLicenseMap = jsonDecode(jsonString);
print(jsonString);
print(responseCarLicenseMap);
print(responseCarLicenseMap['plate_number']);
} else {
print("JSON string not found");
}
// Rest of your code...
} else {
print('Request failed with status: ${response.statusCode}');
print('Request failed with status: ${response.body}');
}
} else {
print('No image selected');
}
}
Future<void> generateBackCarLicenseJordanContent() async {
await pickImage();
isloading = true;
update();
if (image != null) {
final imageBytes = await image.readAsBytes();
final imageData = base64Encode(imageBytes);
var requestBody = jsonEncode({
'contents': [
{
'parts': [
{
'inlineData': {
'mimeType': 'image/jpeg',
'data': imageData,
},
},
{
'text':
'write json output from extracting car license back face for these key ,vin,fuelType,passengerType,curbWeight,insuranceCompany,policyNumber,notes,insuranceType and output it json .dont add data else this image',
},
],
},
],
'generationConfig': {
'temperature': 0.4,
'topK': 343,
'topP': 1,
'maxOutputTokens': 4096,
'stopSequences': [],
},
'safetySettings': [
{
'category': 'HARM_CATEGORY_HARASSMENT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_HATE_SPEECH',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
{
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
},
],
});
print(requestBody);
final response = await http.post(
Uri.parse(
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
headers: {'Content-Type': 'application/json'},
body: requestBody,
);
isloading = false;
update();
if (response.statusCode == 200) {
var responseData = jsonDecode(response.body);
// Process the responseData as needed
// print(responseData);
var result =
responseData['candidates'][0]['content']['parts'][0]['text'];
// print(jsonEncode(result));
// print((result));
// print(result['dob']);
RegExp regex = RegExp(r"```json([^`]*)```");
String? jsonString =
regex.firstMatch(responseData.toString())?.group(1)?.trim();
if (jsonString != null) {
// Convert the JSON object to a String
jsonString = jsonEncode(json.decode(jsonString));
responseBackCarLicenseMap = jsonDecode(jsonString);
// print(jsonString);
print(responseBackCarLicenseMap);
// print(responseCarLicenseMap['plate_number']);
} else {
print("JSON string not found");
}
// Rest of your code...
} else {
print('Request failed with status: ${response.statusCode}');
print('Request failed with status: ${response.body}');
}
} else {
print('No image selected');
}
}
Future<void> getFromCarRegistration() async {
await pickImage();
if (image != null) {

View File

@@ -24,6 +24,7 @@ class LocationController extends GetxController {
void onInit() async {
super.onInit();
location = Location();
totalPoints = Get.find<CaptainWalletController>().totalPoints;
getLocation();
}

View File

@@ -185,6 +185,7 @@ class HomeCaptainController extends GetxController {
getPaymentToday();
getAllPayment();
startPeriodicExecution();
onMapCreated(mapHomeCaptaiController!);
getRefusedOrderByCaptain();
totalPoints = Get.find<CaptainWalletController>().totalPoints;
super.onInit();

View File

@@ -31,11 +31,17 @@ class MapDriverController extends GetxController {
Set<Marker> markers = {};
late String passengerLocation;
late String passengerDestination;
late String step0;
late String step1;
late String step2;
late String step3;
late String step4;
late String duration;
late String distance;
late String name;
late String phone;
late String rideId;
late String isHaveSteps;
late String paymentAmount;
late String paymentMethod;
late String passengerId;
@@ -311,20 +317,15 @@ class MapDriverController extends GetxController {
),
);
// Update the `markers` set and call the `update()` method on the controller to notify the view that the marker position has changed.
update();
// No recursive call here. The marker update will be triggered externally.
// Optionally, you can animate the camera to the new location after updating the marker.
mapController!.animateCamera(
CameraUpdate.newLatLng(locationController.myLocation),
);
update();
}
void addCustomCarIcon() {
ImageConfiguration config = ImageConfiguration(
size: Size(Get.width * .6, Get.height * .6),
ImageConfiguration config = const ImageConfiguration(
size: Size(20, 20),
// scale: 1.0,
);
BitmapDescriptor.fromAssetImage(config, 'assets/images/car.png')
@@ -441,13 +442,25 @@ class MapDriverController extends GetxController {
rideId = Get.arguments['rideId'];
durationOfRideValue = Get.arguments['durationOfRideValue'];
paymentAmount = Get.arguments['paymentAmount'];
paymentMethod = Get.arguments['paymentMethod'];
isHaveSteps = Get.arguments['isHaveSteps'];
step0 = Get.arguments['step0'];
step1 = Get.arguments['step1'];
step2 = Get.arguments['step2'];
step3 = Get.arguments['step3'];
step4 = Get.arguments['step4'];
String lat = Get.find<LocationController>().myLocation.latitude.toString();
String lng = Get.find<LocationController>().myLocation.longitude.toString();
String origin = '$lat,$lng';
// Set the origin and destination coordinates for the Google Maps directions request.
getMap(origin, passengerLocation);
await getMapDestination(passengerLocation, passengerDestination);
isHaveSteps == 'haveSteps'
? (
await getMapDestination(step0, step1),
await getMapDestination(step1, step2),
await getMapDestination(step2, step3),
await getMapDestination(step3, step4),
)
: await getMapDestination(passengerLocation, passengerDestination);
addCustomCarIcon();
// updateMarker();
startTimerToShowPassengerInfoWindowFromDriver();

View File

@@ -67,12 +67,12 @@ class MapPassengerController extends GetxController {
late LatLng newPointLocation3 = const LatLng(32.115295, 36.064773);
late LatLng newPointLocation4 = const LatLng(32.115295, 36.064773);
LatLng myDestination = const LatLng(32.115295, 36.064773);
final List<LatLng> polylineCoordinates = [];
final List<LatLng> polylineCoordinates0 = [];
final List<LatLng> polylineCoordinates1 = [];
final List<LatLng> polylineCoordinates2 = [];
final List<LatLng> polylineCoordinates3 = [];
final List<LatLng> polylineCoordinates4 = [];
List<LatLng> polylineCoordinates = [];
List<LatLng> polylineCoordinates0 = [];
List<LatLng> polylineCoordinates1 = [];
List<LatLng> polylineCoordinates2 = [];
List<LatLng> polylineCoordinates3 = [];
List<LatLng> polylineCoordinates4 = [];
List<List<LatLng>> polylineCoordinatesPointsAll = [];
List<LatLng> carsLocationByPassenger = [];
List<LatLng> driverCarsLocationToPassengerAfterApplied = [];
@@ -187,7 +187,8 @@ class MapPassengerController extends GetxController {
late Duration durationToAdd;
late DateTime newTime = DateTime.now();
int hours = 0;
int minutes = 0;
void onChangedPassengerCount(int newValue) {
selectedPassengerCount = newValue;
update();
@@ -573,7 +574,15 @@ class MapPassengerController extends GetxController {
rideTimerBegin.toString(),
dataCarsLocationByPassenger['message'][carsOrder]['driver_id']
.toString(),
durationToRide.toString()
durationToRide.toString(),
Get.find<WayPointController>().wayPoints.length > 1
? 'haveSteps'
: 'startEnd',
placesCoordinate[0],
placesCoordinate[1],
placesCoordinate[2],
placesCoordinate[3],
placesCoordinate[4],
];
FirebaseMessagesController().sendNotificationToDriverMAP(
'Order',
@@ -636,6 +645,14 @@ class MapPassengerController extends GetxController {
cancelRideAfterRejectFromAll();
}
} else if (decod['data'].toString() == 'Cancel') {
remainingTime = 0;
shouldFetch = false;
rideConfirm = false;
FirebaseMessagesController().sendNotificationToDriverMAP(
'Trip Canceled'.tr, '', driverToken, []);
update();
} else {
delayAndFetchRideStatus(
rideId); // Repeat the delay and fetch operation
@@ -807,6 +824,7 @@ class MapPassengerController extends GetxController {
"status": 'Cancel'
});
rideConfirm = false;
totalStepDurations = 0;
shouldFetch = false;
isPassengerChosen = false;
isCashConfirmPageShown = false;
@@ -825,6 +843,7 @@ class MapPassengerController extends GetxController {
if (rideConfirm == false) {
clearPlacesDestination();
clearPolyline();
// clearPolylineAll();
data = [];
changeCancelRidePageShow();
rideConfirm = false;
@@ -834,6 +853,7 @@ class MapPassengerController extends GetxController {
isCashSelectedBeforeConfirmRide = false;
isPickerShown = false;
totalStepDurations = 0;
totalStepDurations = 0;
timeToPassengerFromDriverAfterApplied = 0;
update();
} else {
@@ -852,7 +872,9 @@ class MapPassengerController extends GetxController {
isCashSelectedBeforeConfirmRide = false;
timeToPassengerFromDriverAfterApplied = 0;
totalStepDurations = 0;
totalStepDurations = 0;
changeCancelRidePageShow();
// clearPolylineAll();
remainingTime = 0;
update();
@@ -1073,9 +1095,27 @@ class MapPassengerController extends GetxController {
void clearPolyline() {
polyLines = [];
polylineCoordinates.clear();
// polylineCoordinates = [];
polylineCoordinatesPointsAll[0].clear();
polylineCoordinatesPointsAll[1].clear();
polylineCoordinatesPointsAll[2].clear();
polylineCoordinatesPointsAll[3].clear();
polylineCoordinatesPointsAll[4].clear();
update();
}
// void clearPolylineAll() {
// polylineCoordinatesPointsAll[0].clear();
// polylineCoordinatesPointsAll[1].clear();
// polylineCoordinatesPointsAll[2].clear();
// polylineCoordinatesPointsAll[3].clear();
// polylineCoordinatesPointsAll[4].clear();
// polyLines = [];
// polylineCoordinates.clear();
// update();
// }
void addCustomPicker() {
ImageConfiguration config = const ImageConfiguration(
size: Size(20, 20),
@@ -1111,9 +1151,9 @@ class MapPassengerController extends GetxController {
}
void addCustomCarIcon() {
ImageConfiguration config = ImageConfiguration(
size: Size(Get.width * .6, Get.height * .6),
// size: Size(20, 20),
ImageConfiguration config = const ImageConfiguration(
// size: Size(Get.width * .6, Get.height * .6),
size: Size(20, 20),
// scale: 1.0,
);
BitmapDescriptor.fromAssetImage(config, 'assets/images/car.png')
@@ -1414,19 +1454,23 @@ class MapPassengerController extends GetxController {
int totalStepDurations = 0;
getMapPoints(String origin, String destination, int index) async {
isWayPointStopsSheetUtilGetMap = false;
await getCarsLocationByPassenger();
isLoading = false;
update();
var url =
('${AppLink.googleMapsLink}directions/json?&language=en&avoid=tolls|ferries&destination=$destination&origin=$origin&key=${AK.mapAPIKEY}');
print(url);
// print(url);
var response = await CRUD().getGoogleApi(link: url, payload: {});
data = response['routes'][0]['legs'];
// print(data);
isLoading = false;
int durationToRide0 = data[0]['duration']['value'];
durationToRide = durationToRide + durationToRide0;
print('durationToRide is ${data[0]['duration']['value']}');
print('totalStepDurations is $durationToRide');
update();
durationToRide = durationToRide + int.parse(data[0]['duration']['value']);
// totalStepDurations = totalStepDurations + durationToRide;
final points =
decodePolyline(response["routes"][0]["overview_polyline"]["points"]);
for (int i = 0; i < points.length; i++) {
@@ -1452,20 +1496,20 @@ class MapPassengerController extends GetxController {
// Animate the camera to the adjusted bounds
if (distanceOfDestnation <= 5) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 14));
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 15));
} else if (distanceOfDestnation > 5 && distanceOfDestnation <= 8) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 13));
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 14));
} else if (distanceOfDestnation > 8 && distanceOfDestnation < 16) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 12));
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 13));
} else if (distanceOfDestnation >= 16 && distanceOfDestnation < 30) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 11));
} else if (distanceOfDestnation >= 30 && distanceOfDestnation < 100) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 10));
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 9));
} else if (distanceOfDestnation >= 100) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 7));
}
if (polyLines.isNotEmpty) {
clearPolyline();
// clearPolyline();
} else {
var polyline = Polyline(
polylineId: PolylineId(response["routes"][0]["summary"]),
@@ -1540,18 +1584,21 @@ class MapPassengerController extends GetxController {
print('=================================');
distance = getDistanceFromText(distanceText);
duration = getDistanceFromText(durationText);
durationToAdd = Duration(minutes: duration.toInt());
durationToAdd = Duration(seconds: durationToRide);
print('durationToRide----- $durationToRide');
hours = durationToAdd.inHours;
minutes = (durationToAdd.inMinutes % 60).round();
DateTime currentTime = DateTime.now();
newTime = currentTime.add(durationToAdd);
averageDuration = duration / distance;
costDuration = duration * averageDuration * 0.016;
averageDuration = (durationToRide / 60) / distance;
costDuration = (durationToRide / 60) * averageDuration * 0.016;
var totalDriver1 = cost + costDuration;
totalPassenger = totalDriver1 + (totalDriver1 * .16);
totalDriver = totalDriver1 + (totalDriver1 * .16);
tax = totalPassenger * .04;
totalME = totalPassenger - totalDriver - tax;
tax = totalPassenger * .16;
totalME = totalPassenger - tax;
update();
if (currentTime.hour >= 21) {
if (currentTime.hour >= 22) {
if (distanceText.contains('km')) {
cost = distance * 0.23;
update();
@@ -1570,7 +1617,7 @@ class MapPassengerController extends GetxController {
} else if (currentTime.hour >= 13 && currentTime.hour <= 16) {
if (averageDuration > 2.5) {
if (distanceText.contains('km')) {
cost = distance * 0.23;
cost = distance * 0.25;
update();
} else {
cost = distance * 0.25 / 1000;
@@ -1599,8 +1646,8 @@ class MapPassengerController extends GetxController {
totalPassenger = 1;
update();
if (totalDriver < .5) {
totalDriver = .80;
totalME = .16;
totalDriver = .75;
totalME = .21;
update();
} else {
totalDriver = .90;

View File

@@ -20,6 +20,7 @@ class SplashScreenController extends GetxController
@override
void onInit() {
super.onInit();
animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 7),

View File

@@ -7,6 +7,7 @@ import '../themes/themes.dart';
class LocaleController extends GetxController {
Locale? language;
String countryCode = '';
void restartApp() {
runApp(const MyApp());
}
@@ -30,11 +31,13 @@ class LocaleController extends GetxController {
break;
default:
locale = Locale(Get.deviceLocale!.languageCode);
appTheme = themeEnglish;
break;
}
box.write(BoxName.lang, langcode);
// box.write(BoxName.lang, langcode);
Get.changeTheme(appTheme);
Get.updateLocale(locale);
restartApp();