6/30/1
This commit is contained in:
@@ -44,6 +44,7 @@ class MapPassengerController extends GetxController {
|
||||
TextEditingController wayPoint3Controller = TextEditingController();
|
||||
TextEditingController wayPoint4Controller = TextEditingController();
|
||||
TextEditingController sosPhonePassengerProfile = TextEditingController();
|
||||
TextEditingController whatsAppLocationText = TextEditingController();
|
||||
final sosFormKey = GlobalKey<FormState>();
|
||||
final increaseFeeFormKey = GlobalKey<FormState>();
|
||||
List data = [];
|
||||
@@ -111,6 +112,7 @@ class MapPassengerController extends GetxController {
|
||||
bool isDriverArrivePassenger = false;
|
||||
bool startLocationFromMap = false;
|
||||
bool isAnotherOreder = false;
|
||||
bool isWhatsAppOrder = false;
|
||||
bool passengerStartLocationFromMap = false;
|
||||
bool workLocationFromMap = false;
|
||||
bool homeLocationFromMap = false;
|
||||
@@ -472,6 +474,11 @@ class MapPassengerController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
void changeIsWhatsAppOrder(bool val) {
|
||||
isWhatsAppOrder = val;
|
||||
update();
|
||||
}
|
||||
|
||||
void sendSMS(String to) async {
|
||||
// Get the driver's phone number.
|
||||
String driverPhone =
|
||||
@@ -682,10 +689,11 @@ class MapPassengerController extends GetxController {
|
||||
box.write(BoxName.passengerWalletTotal, '0');
|
||||
if (box.read(BoxName.parentTripSelected) == true) {
|
||||
FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
"Finish Monitor",
|
||||
"Finish Monitor".tr,
|
||||
"Finish Monitor".tr,
|
||||
box.read(BoxName.tokenParent),
|
||||
[],
|
||||
'order1.wav',
|
||||
);
|
||||
box.write(BoxName.parentTripSelected, false);
|
||||
box.remove(BoxName.tokenParent);
|
||||
@@ -878,6 +886,72 @@ class MapPassengerController extends GetxController {
|
||||
}));
|
||||
}
|
||||
|
||||
Map<String, double>? extractCoordinatesFromWhatsAppLink(String link) {
|
||||
try {
|
||||
Uri uri = Uri.parse(link);
|
||||
|
||||
if (uri.host == 'maps.google.com') {
|
||||
String? query = uri.queryParameters['q'];
|
||||
|
||||
if (query != null) {
|
||||
List<String> coordinates = query.split(',');
|
||||
|
||||
if (coordinates.length == 2) {
|
||||
double latitude = double.parse(coordinates[0]);
|
||||
double longitude = double.parse(coordinates[1]);
|
||||
|
||||
return {
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error parsing WhatsApp location link: $e');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
double latitudeWhatsApp = 0;
|
||||
double longitudeWhatsApp = 0;
|
||||
void handleWhatsAppLink(String link) {
|
||||
Map<String, double>? coordinates = extractCoordinatesFromWhatsAppLink(link);
|
||||
|
||||
if (coordinates != null) {
|
||||
latitudeWhatsApp = coordinates['latitude']!;
|
||||
longitudeWhatsApp = coordinates['longitude']!;
|
||||
|
||||
print(
|
||||
'Extracted coordinates: Lat: $latitudeWhatsApp, Long: $longitudeWhatsApp');
|
||||
// Use these coordinates in your app as needed
|
||||
} else {
|
||||
print('Failed to extract coordinates from the link');
|
||||
}
|
||||
}
|
||||
|
||||
// Example usage
|
||||
void someFunction() {
|
||||
String whatsAppLink = 'https://maps.google.com/maps?q=37.4220,-122.0841';
|
||||
handleWhatsAppLink(whatsAppLink);
|
||||
}
|
||||
|
||||
void goToWhatappLocation() async {
|
||||
if (sosFormKey.currentState!.validate()) {
|
||||
changeIsWhatsAppOrder(true);
|
||||
Get.back();
|
||||
handleWhatsAppLink(whatsAppLocationText.text);
|
||||
myDestination = LatLng(latitudeWhatsApp, longitudeWhatsApp);
|
||||
await mapController?.animateCamera(CameraUpdate.newLatLng(
|
||||
LatLng(passengerLocation.latitude, passengerLocation.longitude)));
|
||||
changeMainBottomMenuMap();
|
||||
passengerStartLocationFromMap = true;
|
||||
isPickerShown = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
int currentTimeSearchingCaptainWindow = 0;
|
||||
late String driverPhone = '';
|
||||
late String driverRate = '';
|
||||
@@ -939,7 +1013,8 @@ class MapPassengerController extends GetxController {
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString()
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
}).then((value) {
|
||||
// List<String> body = [
|
||||
rideId = jsonDecode(value)['message'];
|
||||
@@ -987,12 +1062,15 @@ class MapPassengerController extends GetxController {
|
||||
passengerRate.toStringAsFixed(2),
|
||||
]; //
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Order',
|
||||
jsonDecode(value)['message'].toString(),
|
||||
dataCarsLocationByPassenger['message'][carsOrder]['token'].toString(),
|
||||
body,
|
||||
// polylineCoordinates.toString()
|
||||
);
|
||||
'Order'.tr,
|
||||
jsonDecode(value)['message'].toString(),
|
||||
dataCarsLocationByPassenger['message'][carsOrder]['token']
|
||||
.toString(),
|
||||
body,
|
||||
'order.wav'
|
||||
|
||||
// polylineCoordinates.toString()
|
||||
);
|
||||
});
|
||||
delayAndFetchRideStatus(rideId);
|
||||
if (shouldFetch == false) {
|
||||
@@ -1188,9 +1266,11 @@ class MapPassengerController extends GetxController {
|
||||
driversToken.remove(driverToken);
|
||||
for (var i = 1; i < driversToken.length; i++) {
|
||||
FirebaseMessagesController().sendNotificationToAnyWithoutData(
|
||||
'Order Applied',
|
||||
'$driverName Apply order\nTake attention in other order'.tr,
|
||||
driversToken[i]);
|
||||
'Order Applied',
|
||||
'$driverName Apply order\nTake attention in other order'.tr,
|
||||
driversToken[i],
|
||||
'start.wav',
|
||||
);
|
||||
}
|
||||
// }
|
||||
}
|
||||
@@ -1212,6 +1292,26 @@ class MapPassengerController extends GetxController {
|
||||
'northeastLat': bounds.northeast.latitude.toString(),
|
||||
'northeastLon': bounds.northeast.longitude.toString(),
|
||||
});
|
||||
} else if (box.read(BoxName.carType) == 'Speed') {
|
||||
res = await CRUD().get(
|
||||
link: AppLink.getCarsLocationByPassengerSpeed,
|
||||
payload: {
|
||||
'southwestLat': bounds.southwest.latitude.toString(),
|
||||
'southwestLon': bounds.southwest.longitude.toString(),
|
||||
'northeastLat': bounds.northeast.latitude.toString(),
|
||||
'northeastLon': bounds.northeast.longitude.toString(),
|
||||
},
|
||||
);
|
||||
} else if (box.read(BoxName.carType) == 'Delivery') {
|
||||
res = await CRUD().get(
|
||||
link: AppLink.getCarsLocationByPassengerDelivery,
|
||||
payload: {
|
||||
'southwestLat': bounds.southwest.latitude.toString(),
|
||||
'southwestLon': bounds.southwest.longitude.toString(),
|
||||
'northeastLat': bounds.northeast.latitude.toString(),
|
||||
'northeastLon': bounds.northeast.longitude.toString(),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
res = await CRUD()
|
||||
.get(link: AppLink.getCarsLocationByPassenger, payload: {
|
||||
@@ -1373,10 +1473,12 @@ class MapPassengerController extends GetxController {
|
||||
} else if (res1['status'] == 'success') {
|
||||
var tokenParent = res1['data'][0]['token'];
|
||||
FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
"Trip Monitoring",
|
||||
"Trip Monitoring".tr,
|
||||
tokenParent,
|
||||
[rideId, driverId]);
|
||||
"Trip Monitoring".tr,
|
||||
"Trip Monitoring".tr,
|
||||
tokenParent,
|
||||
[rideId, driverId],
|
||||
'order1.wav',
|
||||
);
|
||||
box.write(BoxName.parentTripSelected, true);
|
||||
box.write(BoxName.tokenParent, tokenParent);
|
||||
}
|
||||
@@ -1519,7 +1621,12 @@ class MapPassengerController extends GetxController {
|
||||
"status": 'Cancel'
|
||||
});
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Cancel Trip', 'Trip Cancelled'.tr, driverToken, []);
|
||||
'Cancel Trip'.tr,
|
||||
'Trip Cancelled'.tr,
|
||||
driverToken,
|
||||
[],
|
||||
'cancel.wav',
|
||||
);
|
||||
}
|
||||
// rideConfirm = false;
|
||||
// shouldFetch = false;
|
||||
@@ -2152,8 +2259,10 @@ class MapPassengerController extends GetxController {
|
||||
data = response['routes'][0]['legs'];
|
||||
box.remove(BoxName.tripData);
|
||||
box.write(BoxName.tripData, response);
|
||||
startNameAddress = data[0]['start_address'];
|
||||
endNameAddress = data[0]['end_address'];
|
||||
|
||||
startNameAddress = shortenAddress(data[0]['start_address']);
|
||||
print('data[0][start_address]: ${data[0]['start_address']}');
|
||||
endNameAddress = shortenAddress(data[0]['end_address']);
|
||||
isLoading = false;
|
||||
newStartPointLocation = LatLng(
|
||||
data[0]["start_location"]['lat'], data[0]["start_location"]['lng']);
|
||||
@@ -2220,6 +2329,43 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
String shortenAddress(String fullAddress) {
|
||||
// Split the address into parts
|
||||
List<String> parts = fullAddress.split('،');
|
||||
|
||||
// Remove any leading or trailing whitespace from each part
|
||||
parts = parts.map((part) => part.trim()).toList();
|
||||
|
||||
// Remove any empty parts
|
||||
parts = parts.where((part) => part.isNotEmpty).toList();
|
||||
|
||||
// Initialize the short address
|
||||
String shortAddress = '';
|
||||
|
||||
// Add the first part (usually the most specific location)
|
||||
if (parts.isNotEmpty) {
|
||||
shortAddress += parts[0];
|
||||
}
|
||||
|
||||
// Add the district or area name (usually the third part in this format)
|
||||
if (parts.length > 2) {
|
||||
shortAddress += '، ${parts[2]}';
|
||||
}
|
||||
|
||||
// Add the country (usually the last part)
|
||||
if (parts.length > 1) {
|
||||
shortAddress += '، ${parts.last}';
|
||||
}
|
||||
|
||||
// Remove any part that's just numbers (like postal codes)
|
||||
shortAddress = shortAddress
|
||||
.split('،')
|
||||
.where((part) => !RegExp(r'^[0-9 ]+$').hasMatch(part.trim()))
|
||||
.join('،');
|
||||
|
||||
return shortAddress;
|
||||
}
|
||||
|
||||
double distanceOfDestination = 0;
|
||||
bool haveSteps = false;
|
||||
late LatLng latestPosition;
|
||||
|
||||
Reference in New Issue
Block a user