This commit is contained in:
Hamza-Ayed
2024-09-19 07:05:19 +03:00
parent a65e7e5562
commit 2e3ce78fe8
12 changed files with 393 additions and 223 deletions

View File

@@ -429,7 +429,7 @@ class FirebaseMessagesController extends GetxController {
));
}
void sendNotificationAll(String title, body) async {
void sendNotificationAll(String title, body, tone) async {
// Get the token you want to subtract.
String token = box.read(BoxName.tokenFCM);
tokens = box.read(BoxName.tokens);
@@ -441,25 +441,41 @@ class FirebaseMessagesController extends GetxController {
tokens = box.read(BoxName.tokens);
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=${AK.serverAPI}'
},
body: jsonEncode({
'notification': <String, dynamic>{
.post(
Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'key=${AK.serverAPI}'
},
body: jsonEncode({
'message': {
'token': token,
'notification': {
'title': title,
'body': body,
'sound': 'ding.wav'
},
'priority': 'high',
'data': <String, dynamic>{
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
// 'data': {
// 'DriverList': jsonEncode(data),
// },
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'to': tokens[i],
}))
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
},
},
},
},
}),
)
.whenComplete(() {})
.catchError((e) {});
}
@@ -533,11 +549,15 @@ class FirebaseMessagesController extends GetxController {
'body': body,
},
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
@@ -603,11 +623,15 @@ class FirebaseMessagesController extends GetxController {
'body': body,
},
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
@@ -716,11 +740,15 @@ class FirebaseMessagesController extends GetxController {
'DriverList': jsonEncode(data),
},
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
@@ -746,7 +774,7 @@ class FirebaseMessagesController extends GetxController {
}
void sendNotificationToDriverMapPolyline(String title, String body,
String token, List<String> data, String polylineJson) async {
String token, List<String> data, String polylineJson, String tone) async {
try {
String serviceAccountKeyJson = '''{
"type": "service_account",
@@ -778,18 +806,32 @@ class FirebaseMessagesController extends GetxController {
'Authorization': 'Bearer $accessToken',
},
body: jsonEncode({
'notification': <String, dynamic>{
'title': title,
'body': body,
// 'sound': 'tone2.wav',
'sound': 'order.wav'
'message': {
'token': token,
'notification': {
'title': title,
'body': body,
},
'data': {
'DriverList': jsonEncode(data),
},
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
},
},
},
},
'data': {
'DriverList': data,
'PolylineJson': polylineJson,
},
'priority': 'high',
'to': token,
}),
);

View File

@@ -1017,10 +1017,10 @@ class MapPassengerController extends GetxController {
late String make = '';
late String licensePlate = '';
confirmRideForFirstDriver() async {
startCarLocationSearch(box.read(BoxName.carType));
// startCarLocationSearch(box.read(BoxName.carType));
// await getCarsLocationByPassengerAndReloadMarker(
// box.read(BoxName.carType), 7000);
await getNearestDriverByPassengerLocationAPIGOOGLE();
// box.read(BoxName.carType), 7000);
// await getNearestDriverByPassengerLocationAPIGOOGLE();
Log.print('dataCarsLocationByPassenger: ${dataCarsLocationByPassenger}');
if (dataCarsLocationByPassenger != 'failure' ||
dataCarsLocationByPassenger != null) {
@@ -1258,12 +1258,8 @@ class MapPassengerController extends GetxController {
];
Log.print('body: ${body}');
for (var i = 1; i < driversToken.length; i++) {
FirebaseMessagesController().sendNotificationToDriverMapPolyline(
'OrderSpeed',
rideId.toString(),
driversToken[i],
body,
polylineCoordinates.toString());
FirebaseMessagesController().sendNotificationToDriverMAP('OrderSpeed',
rideId.toString(), driversToken[i], body, 'order.wav');
}
(rideId);
@@ -1291,6 +1287,8 @@ class MapPassengerController extends GetxController {
if (res.toString() == 'waiting' && tick >= 15) {
timer.cancel(); // Stop the current timer
showAndResearchForCaptain();
//TODO add to wait
confirmRideForAllDriverAvailable();
// delayAndFetchRideStatusForAllDriverAvailable(rideId);
} else if (res.toString() == 'Apply') {
// todo play sound
@@ -1314,7 +1312,9 @@ class MapPassengerController extends GetxController {
// No need to recall delayAndFetchRideStatus as Timer.periodic is already running
update();
// }
tick++;
if (tick < 19) {
tick++;
}
} else {
timer.cancel();
// Stop the timer if remainingTimeToPassengerFromDriverAfterApplied <= 0
@@ -1343,7 +1343,7 @@ class MapPassengerController extends GetxController {
Log.print('tick delayAndFetchRideStatusForAllDriverAvailable: ${tick}');
void fetchRideStatus() async {
if (attemptCounter < maxAttempts && !isApplied && tick < 20) {
if (attemptCounter < maxAttempts && !isApplied || tick < 20) {
attemptCounter++;
tick++;
var res = await getRideStatus(rideId);
@@ -1760,7 +1760,7 @@ class MapPassengerController extends GetxController {
'northeastLon': bounds.northeast.longitude.toString(),
});
break;
case 'Delivery':
case 'Scooter':
res = await CRUD()
.get(link: AppLink.getCarsLocationByPassengerDelivery, payload: {
'southwestLat': bounds.southwest.latitude.toString(),
@@ -1778,6 +1778,15 @@ class MapPassengerController extends GetxController {
'northeastLon': bounds.northeast.longitude.toString(),
});
break;
case 'Pink Bike':
res = await CRUD()
.get(link: AppLink.getCarsLocationByPassengerPinkBike, payload: {
'southwestLat': bounds.southwest.latitude.toString(),
'southwestLon': bounds.southwest.longitude.toString(),
'northeastLat': bounds.northeast.latitude.toString(),
'northeastLon': bounds.northeast.longitude.toString(),
});
break;
default:
res = await CRUD()
.get(link: AppLink.getCarsLocationByPassenger, payload: {
@@ -1796,11 +1805,29 @@ class MapPassengerController extends GetxController {
} else {
noCarString = false;
dataCarsLocationByPassenger = jsonDecode(res);
driverId = dataCarsLocationByPassenger['message'][carsOrder]
['driver_id']
.toString();
gender = dataCarsLocationByPassenger['message'][carsOrder]['gender']
.toString();
// Check if 'message' is present and not null
if (dataCarsLocationByPassenger['message'] != null &&
dataCarsLocationByPassenger['message'].isNotEmpty) {
// Check if carsOrder is within bounds
if (carsOrder < dataCarsLocationByPassenger['message'].length) {
driverId = dataCarsLocationByPassenger['message'][carsOrder]
['driver_id']
.toString();
gender = dataCarsLocationByPassenger['message'][carsOrder]['gender']
.toString();
driverToken = dataCarsLocationByPassenger['message'][carsOrder]
['token']
.toString();
} else {
print('carsOrder is out of bounds for message array');
return false;
}
} else {
// Get.defaultDialog(title: 'No cars available ');
print('No cars available or message is null');
return false;
}
carsLocationByPassenger.clear(); // Clear existing markers

View File

@@ -4,6 +4,10 @@ class MyTranslation extends Translations {
@override
Map<String, Map<String, String>> get keys => {
"ar": {
"Price of trip": "سعر الرحلة",
"For Speed and Delivery trips, the price is calculated dynamically. For Comfort trips, the price is based on time and distance":
"بالنسبة لرحلات السرعة والتوصيل، يتم حساب السعر ديناميكياً. بالنسبة لرحلات الراحة، يتم حساب السعر بناءً على الوقت والمسافة",
"Phone Wallet Saved Successfully": "تم حفظ المحفظة الهاتفية بنجاح",
"Add wallet phone you use": "أضف محفظة الهاتف التي تستخدمها",
"Update Available": "تحديث متوفر",
'Phone number must be exactly 11 digits long':