Fixes & Updates - 2026-06-01: Integrate Back-End v3 updates, fix call/connection issues across apps

This commit is contained in:
Hamza-Ayed
2026-06-01 23:35:29 +03:00
parent 8f555691b9
commit cbf693c804
56 changed files with 6091 additions and 1217 deletions

View File

@@ -4,6 +4,7 @@ import 'package:sefer_driver/controller/home/captin/home_captain_controller.dart
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_speed_request.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import 'package:sefer_driver/controller/voice_call_controller.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@@ -75,6 +76,24 @@ class FirebaseMessagesController extends GetxController {
await fcmToken.subscribeToTopic("drivers"); // أو "users" حسب نوع المستخدم
print("Subscribed to 'drivers' topic ✅");
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? message) async {
if (message != null && message.data.isNotEmpty) {
Log.print("🔔 FCM getInitialMessage payload: ${message.data}");
String? category = message.data['category'] ?? message.data['type'];
if (category == 'ORDER' || category == 'Order' || category == 'OrderVIP' || message.data.containsKey('DriverList')) {
String? myListString = message.data['DriverList'];
if (myListString != null && myListString.isNotEmpty) {
await storage.write(key: 'pending_driver_list', value: myListString);
Log.print("💾 Saved pending driver list to secure storage from getInitialMessage");
}
} else {
Future.delayed(const Duration(milliseconds: 1500), () {
fireBaseTitles(message);
});
}
}
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// If the app is in the background or terminated, show a system tray message
RemoteNotification? notification = message.notification;
@@ -113,11 +132,22 @@ class FirebaseMessagesController extends GetxController {
// if (Platform.isAndroid) {
// notificationController.showNotification(title, body, 'order', '');
// }
// 🔥 [Fix FCM-Guard] منع إعاقة الرحلة النشطة بطلبات جديدة عبر FCM
String currentRideStatus = box.read(BoxName.rideStatus) ?? '';
if (currentRideStatus == 'Begin' ||
currentRideStatus == 'Apply' ||
currentRideStatus == 'Arrived') {
Log.print(
"⛔ [FCM] Ignoring ORDER notification — driver has active ride ($currentRideStatus)");
break;
}
var myListString = message.data['DriverList'];
if (myListString != null) {
var myList = jsonDecode(myListString) as List<dynamic>;
driverToken = myList[14].toString();
Get.put(HomeCaptainController()).changeRideId();
Get.put(HomeCaptainController(), permanent: true).changeRideId();
update();
Get.toNamed('/OrderRequestPage', arguments: {
'myListString': myListString,
@@ -231,6 +261,20 @@ class FirebaseMessagesController extends GetxController {
mySnackbarSuccess("The order has been accepted by another driver.".tr);
break;
case 'incoming_call':
case 'INCOMING_CALL':
final sessionId = message.data['session_id'];
final callerName = message.data['caller_name'];
final rideId = message.data['ride_id'];
if (sessionId != null && callerName != null && rideId != null) {
Get.find<VoiceCallController>().receiveCall(
sessionIdVal: sessionId.toString(),
remoteNameVal: callerName.toString(),
rideIdVal: rideId.toString(),
);
}
break;
default:
Log.print('Received unhandled notification category: $category');
// Optionally show a generic notification

View File

@@ -104,6 +104,7 @@ class NotificationController extends GetxController {
String endLoc = _getVal(data, 30);
String paxName = _getVal(data, 8);
// String rating = _getVal(data, 33);
String isHaveSteps = _getVal(data, 20);
// تنسيق النص ليكون 4 أسطر واضحة
formattedBigText = "👤 $paxName\n"
@@ -111,6 +112,10 @@ class NotificationController extends GetxController {
"🟢 من: $startLoc\n"
"🏁 إلى: $endLoc";
if (isHaveSteps == 'true') {
formattedBigText += "\n🛑 هذه الرحلة تحتوي على نقاط توقف!";
}
summaryText = 'سعر الرحلة: $price';
} catch (e) {
print("Error formatting notification text: $e");
@@ -181,11 +186,16 @@ class NotificationController extends GetxController {
final details =
NotificationDetails(android: androidDetails, iOS: iosDetails);
String briefBody = "$price - مسافة $formattedBigText";
if (_getVal(jsonDecode(myListString), 20) == 'true') {
briefBody = "🛑 (متعددة التوقفات) $price - مسافة $formattedBigText";
}
// عرض الإشعار
await _flutterLocalNotificationsPlugin.show(
id: 1001, // ID ثابت لاستبدال الإشعار القديم
title: title,
body: "$price - مسافة $formattedBigText", // نص مختصر يظهر في البار العلوي
body: briefBody, // نص مختصر يظهر في البار العلوي
notificationDetails: details,
payload: jsonEncode({
'type': 'Order',
@@ -298,7 +308,7 @@ class NotificationController extends GetxController {
// حماية من الكراش: التأكد من وجود HomeCaptainController
if (!Get.isRegistered<HomeCaptainController>()) {
print("♻️ Reviving HomeCaptainController...");
Get.put(HomeCaptainController());
Get.put(HomeCaptainController(), permanent: true);
} else {
Get.find<HomeCaptainController>().changeRideId();
}