24-12/27/1

This commit is contained in:
Hamza-Ayed
2024-12-27 21:25:40 +03:00
parent d0dd09dc6c
commit f9f19c33ef
8 changed files with 423 additions and 683 deletions

View File

@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/controller/home/captin/home_captain_controller.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
@@ -95,7 +96,7 @@ class FirebaseMessagesController extends GetxController {
}
Future<void> fireBaseTitles(RemoteMessage message) async {
if (message.notification!.title! == 'OrderSpeed'.tr) {
if (message.notification!.title! == 'Order'.tr) {
if (Platform.isAndroid) {
notificationController.showNotification(
message.notification!.title.toString(),
@@ -398,61 +399,6 @@ class FirebaseMessagesController extends GetxController {
}));
}
// Future<dynamic> driverFinishTripDialoge(List<dynamic> driverList) {
// return Get.defaultDialog(
// title: 'Driver Finish Trip'.tr,
// content: const DriverTipWidget(),
// confirm: MyElevatedButton(
// title: 'Yes'.tr,
// onPressed: () async {
// var tip = (Get.find<MapPassengerController>().totalPassenger) *
// (double.parse(box.read(BoxName.tipPercentage.toString())));
// var res = await CRUD().post(link: AppLink.addTips, payload: {
// 'passengerID': box.read(BoxName.passengerID),
// 'driverID': driverList[0].toString(),
// 'rideID': driverList[1].toString(),
// 'tipAmount': tip.toString(),
// });
// await CRUD().post(link: AppLink.addPassengersWallet, payload: {
// 'passenger_id': box.read(BoxName.passengerID).toString(),
// 'balance': ((-1) * tip).toString()
// });
// await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
// 'driverID': driverList[0].toString(),
// 'paymentID': '${Get.find<MapPassengerController>().rideId}tip',
// 'amount': (tip * 100).toString(),
// 'paymentMethod': 'visa-tip',
// });
// if (res != 'failure') {
// FirebaseMessagesController().sendNotificationToAnyWithoutData(
// 'You Have Tips',
// '${'${tip.toString()}\$${' tips\nTotal is'.tr}'} ${tip + (Get.find<MapPassengerController>().totalPassenger)}',
// driverList[2].toString(),
// );
// }
// Get.to(() => RateDriverFromPassenger(), arguments: {
// 'driverId': driverList[0].toString(),
// 'rideId': driverList[1].toString(),
// 'price': driverList[3].toString()
// });
// },
// kolor: AppColor.greenColor,
// ),
// cancel: MyElevatedButton(
// title: 'No,I want'.tr,
// onPressed: () {
// Get.to(() => RateDriverFromPassenger(), arguments: {
// 'driverId': driverList[0].toString(),
// 'rideId': driverList[1].toString(),
// 'price': driverList[3].toString()
// });
// },
// kolor: AppColor.redColor,
// ));
// }
void sendNotificationAll(String title, body, tone) async {
// Get the token you want to subtract.
String token = box.read(BoxName.tokenFCM);
@@ -528,33 +474,6 @@ class FirebaseMessagesController extends GetxController {
}
}
// for (var i = 0; i < tokens.length; i++) {
// http
// .post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
// headers: <String, String>{
// 'Content-Type': 'application/json',
// 'Authorization': 'key=${storage.read(key: BoxName.serverAPI}'
// },
// body: jsonEncode({
// 'notification': <String, dynamic>{
// 'title': title,
// 'body': body,
// 'sound': 'true'
// },
// 'priority': 'high',
// 'data': <String, dynamic>{
// 'click_action': 'FLUTTER_NOTIFICATION_CLICK',
// 'id': '1',
// 'status': 'done'
// },
// 'to': tokens[i],
// }))
// .whenComplete(() {})
// .catchError((e) {
// });
// }
// }
//android/app/src/main/res/raw/iphone_ringtone.wav
void sendNotificationToPassengerToken(
String title, body, token, List<String> map, String tone,
{int retryCount = 2}) async {

View File

@@ -30,23 +30,22 @@ class OrderRequestController extends GetxController {
var myList;
late int hours;
late int minutes;
GoogleMapController? mapController; // Make it nullable
@override
Future<void> onInit() async {
// AudioController audioController = Get.put(AudioController());
print('onInit called');
await initilizeOrderPage();
print('OrderRequestController onInit called');
await initializeOrderPage();
bool isOverlayActive = await FlutterOverlayWindow.isActive();
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
// audioController.playAudio();
// getRefusedOrderByCaptain();
addCustomStartIcon();
addCustomEndIcon();
// calculateConsumptionFuel();
startTimer(
myList[6].toString(),
myList[16].toString(),
);
update();
super.onInit();
}
@@ -59,16 +58,16 @@ class OrderRequestController extends GetxController {
late double lngPassengerDestination;
late double latPassengerDestination;
Future<void> initilizeOrderPage() async {
Future<void> initializeOrderPage() async {
final myListString = Get.arguments['myListString'];
if (Get.arguments['DriverList'] == null ||
Get.arguments['DriverList'].isEmpty) {
myList = jsonDecode(myListString);
Log.print('myList: ${myList}');
Log.print('myList from myListString: ${myList}');
} else {
myList = Get.arguments['DriverList'];
Log.print('myList1: ${myList}');
Log.print('myList from DriverList: ${myList}');
}
body = Get.arguments['body'];
@@ -78,36 +77,58 @@ class OrderRequestController extends GetxController {
minutes = (durationToAdd.inMinutes % 60).round();
startTimerSpeed(myList[6].toString(), body.toString());
// Instead of splitting, directly use the values from the list
// First coordinate pair is at index 0 and 1
latPassengerLocation = double.tryParse(myList[0]) ?? 0.0;
lngPassengerLocation = double.tryParse(myList[1]) ?? 0.0;
// --- Using the provided logic for initialization ---
var cords = myList[0].toString().split(',');
var cordDestination = myList[1].toString().split(',');
// Second coordinate pair is at index 2 and 3
latPassengerDestination = double.tryParse(myList[2]) ?? 0.0;
lngPassengerDestination = double.tryParse(myList[3]) ?? 0.0;
double? parseDouble(String value) {
try {
return double.parse(value);
} catch (e) {
Log.print("Error parsing value: $value");
return null; // or handle the error appropriately
}
}
latPassengerLocation = parseDouble(cords[0]) ?? 0.0;
lngPassengerLocation = parseDouble(cords[1]) ?? 0.0;
latPassengerDestination = parseDouble(cordDestination[0]) ?? 0.0;
lngPassengerDestination = parseDouble(cordDestination[1]) ?? 0.0;
pointsDirection = [
LatLng(latPassengerLocation, lngPassengerLocation),
LatLng(latPassengerDestination, lngPassengerDestination)
];
Log.print('pointsDirection: $pointsDirection');
// Calculate bounds
double minLatitude =
math.min(pointsDirection[0].latitude, pointsDirection[1].latitude);
double maxLatitude =
math.max(pointsDirection[0].latitude, pointsDirection[1].latitude);
double minLongitude =
math.min(pointsDirection[0].longitude, pointsDirection[1].longitude);
double maxLongitude =
math.max(pointsDirection[0].longitude, pointsDirection[1].longitude);
calculateBounds();
update();
}
void onMapCreated(GoogleMapController controller) {
mapController = controller;
animateCameraToBounds();
}
void calculateBounds() {
double minLat = math.min(latPassengerLocation, latPassengerDestination);
double maxLat = math.max(latPassengerLocation, latPassengerDestination);
double minLng = math.min(lngPassengerLocation, lngPassengerDestination);
double maxLng = math.max(lngPassengerLocation, lngPassengerDestination);
bounds = LatLngBounds(
southwest: LatLng(minLatitude, minLongitude),
northeast: LatLng(maxLatitude, maxLongitude),
southwest: LatLng(minLat, minLng),
northeast: LatLng(maxLat, maxLng),
);
Log.print('Calculated Bounds: $bounds');
}
update();
void animateCameraToBounds() {
if (mapController != null) {
mapController!.animateCamera(CameraUpdate.newLatLngBounds(bounds, 80.0));
} else {
Log.print('mapController is null, cannot animate camera.');
}
}
getRideDEtailsForBackgroundOrder(String rideId) async {
@@ -117,10 +138,7 @@ class OrderRequestController extends GetxController {
}
void addCustomStartIcon() async {
// Create the marker with the resized image
ImageConfiguration config = ImageConfiguration(
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
ImageConfiguration config = const ImageConfiguration(size: Size(30, 30));
BitmapDescriptor.asset(
config,
'assets/images/A.png',
@@ -131,8 +149,7 @@ class OrderRequestController extends GetxController {
}
void addCustomEndIcon() {
ImageConfiguration config = ImageConfiguration(
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
ImageConfiguration config = const ImageConfiguration(size: Size(30, 30));
BitmapDescriptor.asset(
config,
'assets/images/b.png',
@@ -149,8 +166,7 @@ class OrderRequestController extends GetxController {
double mpg = 0;
calculateConsumptionFuel() {
mpg = Get.find<HomeCaptainController>().fuelPrice /
12; //todo in register car add mpg in box
mpg = Get.find<HomeCaptainController>().fuelPrice / 12;
}
bool _timerActive = false;
@@ -161,7 +177,6 @@ class OrderRequestController extends GetxController {
await Future.delayed(const Duration(seconds: 1));
progress = i / duration;
remainingTime = duration - i;
update();
}
if (remainingTime == 0 && _timerActive) {
@@ -181,13 +196,11 @@ class OrderRequestController extends GetxController {
await Future.delayed(const Duration(seconds: 1));
progressSpeed = i / durationSpeed;
remainingTimeSpeed = durationSpeed - i;
update();
}
if (remainingTimeSpeed == 0) {
if (applied == false) {
Get.back();
// refuseOrder(box.read(BoxName.driverID), orderID);
}
}
}
@@ -196,39 +209,23 @@ class OrderRequestController extends GetxController {
orderID,
) async {
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
//TODO need review
'driver_id': box.read(BoxName.driverID),
// box.read(BoxName.driverID).toString(),
'order_id': orderID,
'status': 'Refused'
});
await CRUD().post(link: AppLink.updateRides, payload: {
'id': orderID,
// 'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
if (AppLink.endPoint != AppLink.seferCairoServer) {
CRUD().post(link: '${AppLink.endPoint}/rides/update.php', payload: {
'id': orderID,
// 'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
}
// applied = true;
// if (box.read(BoxName.gender).toString() != 'Female') {
// sql.insertData({
// 'order_id': orderID,
// 'created_at': DateTime.now().toString(),
// 'driver_id': box.read(BoxName.driverID).toString(),
// }, TableName.driverOrdersRefuse);
// getRefusedOrderByCaptain();
// }
update();
// Get.back();
// Get.offAll(HomeCaptain());
}
addRideToNotificationDriverString(

View File

@@ -10,12 +10,14 @@ class MyTranslation extends Translations {
"Duration": "المدة",
"Distance": "المسافة",
"Passenger": "الراكب",
"Cost": "التكلفة",
"Cost": "التكلفة", "Order": "طلب",
"Car Type": "نوع ‏الطلب",
"Start the Ride": "ابدأ الرحلة",
"Start the Ride": "ابدأ الرحلة", "Accepted Ride": "تم قبول الرحلة",
"Is the Passenger in your Car?": "هل الراكب في سيارتك؟",
"Don't start trip if passenger not in your car":
"لا تبدأ الرحلة إذا لم يكن الراكب في سيارتك",
"your ride is Accepted": "تم قبول رحلتك",
'Driver Accepted the Ride for You': 'السائق قبل الرحلة لك',
"I Arrive": "لقد وصلت", "Trip is Begin": "بدأت الرحلة",
"You are not near the passenger location":
"أنت لست بالقرب من موقع الراكب",