25-6-23/1

This commit is contained in:
Hamza-Ayed
2025-06-23 02:24:42 +03:00
parent 5eba032887
commit 5050aab9b7
42 changed files with 2387 additions and 1783 deletions

View File

@@ -14,6 +14,7 @@ import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../constant/style.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/auth/captin/criminal_documents_page.dart';
import '../../views/home/Captin/home_captain/home_captin.dart';
import '../../views/home/Captin/orderCaptin/order_speed_request.dart';
@@ -180,6 +181,7 @@ class FirebaseMessagesController extends GetxController {
'Trip Cancelled. The cost of the trip will be added to your wallet.'
.tr, () {
box.write(BoxName.rideStatus, 'Cancel');
Log.print('rideStatus from 184 : ${box.read(BoxName.rideStatus)}');
Get.offAll(HomeCaptain());
});
// cancelTripDialog1();
@@ -341,6 +343,8 @@ class FirebaseMessagesController extends GetxController {
title: 'Ok'.tr,
onPressed: () {
box.write(BoxName.rideStatus, 'Cancel');
Log.print(
'rideStatus from 347 : ${box.read(BoxName.rideStatus)}');
Get.offAll(HomeCaptain());
}));
}
@@ -356,6 +360,8 @@ class FirebaseMessagesController extends GetxController {
title: 'Ok'.tr,
onPressed: () {
box.write(BoxName.rideStatus, 'Cancel');
Log.print(
'rideStatus from 364 : ${box.read(BoxName.rideStatus)}');
Get.offAll(HomeCaptain());
}));
}
@@ -405,7 +411,7 @@ class FirebaseMessagesController extends GetxController {
Future<void> onInit() async {
super.onInit();
try {
var encryptedKey = await storage.read(key: 'FCM_PRIVATE_KEY');
var encryptedKey = await storage.read(key: BoxName.FCM_PRIVATE_KEY);
// Log.print('encryptedKey: ${encryptedKey}');
if (encryptedKey != null) {
serviceAccountKeyJson =
@@ -707,33 +713,40 @@ class FirebaseMessagesController extends GetxController {
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
} else if (response.statusCode == 404) {
// Handle UNREGISTERED token
final responseBody = jsonDecode(response.body);
final errorCode = responseBody['error']['details']?[0]?['errorCode'];
if (errorCode == 'UNREGISTERED') {
print('Token is unregistered/invalid: $token');
// Remove token from your database
await removeInvalidToken(token);
return; // Don't retry for invalid tokens
}
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
const Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToPassengerTokenCALL(
title, body, token, data, tone,
await Future.delayed(const Duration(seconds: 2));
return sendNotificationToDriverMAP(title, body, token, data, tone,
retryCount: retryCount - 1);
}
}
} catch (e) {
print('Error sending notification: $e');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
const Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToPassengerTokenCALL(
title, body, token, data, tone,
retryCount: retryCount - 1);
}
// ... existing error handling ...
}
}
Future<void> removeInvalidToken(String token) async {
// Remove token from your database/storage
// This prevents future attempts to send to invalid tokens
print('Removing invalid token from database: $token');
// Your database cleanup logic here
}
}
class OverlayContent extends StatelessWidget {