26-1-20/1
This commit is contained in:
@@ -20,6 +20,7 @@ import '../../views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import '../../views/home/Captin/orderCaptin/vip_order_page.dart';
|
||||
import '../auth/google_sign.dart';
|
||||
import '../functions/face_detect.dart';
|
||||
import '../home/captin/map_driver_controller.dart';
|
||||
import 'local_notification.dart';
|
||||
|
||||
class FirebaseMessagesController extends GetxController {
|
||||
@@ -80,7 +81,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
AndroidNotification? android = notification?.android;
|
||||
// if (notification != null && android != null) {
|
||||
|
||||
if (message.data.isNotEmpty && message.notification != null) {
|
||||
if (message.data.isNotEmpty) {
|
||||
fireBaseTitles(message);
|
||||
}
|
||||
// if (message.data.isNotEmpty && message.notification != null) {
|
||||
@@ -90,7 +91,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {});
|
||||
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||
if (message.data.isNotEmpty && message.notification != null) {
|
||||
if (message.data.isNotEmpty) {
|
||||
fireBaseTitles(message);
|
||||
}
|
||||
});
|
||||
@@ -110,7 +111,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
case 'ORDER':
|
||||
case 'Order': // Handle both cases for backward compatibility
|
||||
if (Platform.isAndroid) {
|
||||
notificationController.showNotification(title, body, 'tone1', '');
|
||||
notificationController.showNotification(title, body, 'order', '');
|
||||
}
|
||||
var myListString = message.data['DriverList'];
|
||||
if (myListString != null) {
|
||||
@@ -118,7 +119,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
driverToken = myList[14].toString();
|
||||
Get.put(HomeCaptainController()).changeRideId();
|
||||
update();
|
||||
Get.to(() => OrderRequestPage(), arguments: {
|
||||
Get.toNamed('/OrderRequestPage', arguments: {
|
||||
'myListString': myListString,
|
||||
'DriverList': myList,
|
||||
'body': body
|
||||
@@ -147,7 +148,18 @@ class FirebaseMessagesController extends GetxController {
|
||||
notificationController.showNotification(
|
||||
title, 'Passenger Cancel Trip'.tr, 'cancel', '');
|
||||
}
|
||||
cancelTripDialog();
|
||||
Log.print("🔔 FCM: Ride Cancelled by Passenger received.");
|
||||
|
||||
// 1. استخراج السبب (أرسلناه من PHP باسم 'reason')
|
||||
String reason = message.data['reason'] ?? 'No reason provided';
|
||||
|
||||
// 2. توجيه الأمر للكنترولر
|
||||
if (Get.isRegistered<MapDriverController>()) {
|
||||
// استدعاء الحارس (سيتجاهل الأمر إذا كان السوكيت قد سبقه)
|
||||
Get.find<MapDriverController>()
|
||||
.processRideCancelledByPassenger(reason, source: "FCM");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'VIP Order Accepted':
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:sefer_driver/constant/colors.dart';
|
||||
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_speed_request.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
@@ -74,38 +71,6 @@ class NotificationController extends GetxController {
|
||||
sound: RawResourceAndroidNotificationSound(tone),
|
||||
);
|
||||
|
||||
// AndroidNotificationDetails android = AndroidNotificationDetails(
|
||||
// 'high_importance_channel', // Use the same ID as before
|
||||
// 'High Importance Notifications',
|
||||
// importance: Importance.high,
|
||||
// priority: Priority.high,
|
||||
// styleInformation: bigTextStyleInformation,
|
||||
// playSound: true,
|
||||
// sound: RawResourceAndroidNotificationSound(tone),
|
||||
// // audioAttributesUsage: AudioAttributesUsage.alarm,
|
||||
// visibility: NotificationVisibility.public,
|
||||
// autoCancel: false,
|
||||
// color: AppColor.primaryColor,
|
||||
// showProgress: true,
|
||||
// showWhen: true,
|
||||
// ongoing: true,
|
||||
// enableVibration: true,
|
||||
// vibrationPattern: Int64List.fromList([0, 1000, 500, 1000]),
|
||||
// timeoutAfter: 14500,
|
||||
// setAsGroupSummary: true,
|
||||
// subText: message, fullScreenIntent: true,
|
||||
// actions: [
|
||||
// AndroidNotificationAction(
|
||||
// allowGeneratedReplies: true,
|
||||
// 'id',
|
||||
// title.tr,
|
||||
// titleColor: AppColor.blueColor,
|
||||
// showsUserInterface: true,
|
||||
// )
|
||||
// ],
|
||||
// category: AndroidNotificationCategory.message,
|
||||
// );
|
||||
|
||||
DarwinNotificationDetails ios = const DarwinNotificationDetails(
|
||||
sound: 'default',
|
||||
presentAlert: true,
|
||||
|
||||
@@ -1,41 +1,44 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../print.dart';
|
||||
import 'package:get/get.dart'; // للترجمة .tr
|
||||
|
||||
class NotificationService {
|
||||
// تأكد من أن هذا هو الرابط الصحيح لملف الإرسال
|
||||
static const String _serverUrl =
|
||||
'https://syria.intaleq.xyz/intaleq/fcm/send_fcm.php';
|
||||
'https://api.intaleq.xyz/intaleq/ride/firebase/send_fcm.php';
|
||||
|
||||
static Future<void> sendNotification({
|
||||
required String target,
|
||||
required String title,
|
||||
required String body,
|
||||
required String? category, // <-- [الإضافة الأولى]
|
||||
required String category, // إلزامي للتصنيف
|
||||
String? tone,
|
||||
List<String>? driverList,
|
||||
bool isTopic = false,
|
||||
}) async {
|
||||
try {
|
||||
final Map<String, dynamic> payload = {
|
||||
// 1. تجهيز البيانات المخصصة (Data Payload)
|
||||
Map<String, dynamic> customData = {};
|
||||
|
||||
customData['category'] = category;
|
||||
|
||||
// إذا كان هناك قائمة سائقين/ركاب، نضعها هنا
|
||||
if (driverList != null && driverList.isNotEmpty) {
|
||||
// نرسلها كـ JSON String لأن FCM v1 يدعم String Values فقط في الـ data
|
||||
customData['driverList'] = jsonEncode(driverList);
|
||||
}
|
||||
|
||||
// 2. تجهيز الطلب الرئيسي للسيرفر
|
||||
final Map<String, dynamic> requestPayload = {
|
||||
'target': target,
|
||||
'title': title,
|
||||
'body': body,
|
||||
'isTopic': isTopic,
|
||||
'data':
|
||||
customData, // 🔥🔥 التغيير الجوهري: وضعنا البيانات داخل "data" 🔥🔥
|
||||
};
|
||||
|
||||
if (category != null) {
|
||||
payload['category'] = category; // <-- [الإضافة الثانية]
|
||||
}
|
||||
|
||||
if (tone != null) {
|
||||
payload['tone'] = tone;
|
||||
}
|
||||
|
||||
if (driverList != null) {
|
||||
// [مهم] تطبيق السائق يرسل passengerList
|
||||
payload['passengerList'] = jsonEncode(driverList);
|
||||
requestPayload['tone'] = tone;
|
||||
}
|
||||
|
||||
final response = await http.post(
|
||||
@@ -43,17 +46,18 @@ class NotificationService {
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(payload),
|
||||
body: jsonEncode(requestPayload),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
Log.print('✅ Notification sent successfully.');
|
||||
print('✅ Notification sent successfully.');
|
||||
// print('Response: ${response.body}');
|
||||
} else {
|
||||
Log.print(
|
||||
'❌ Failed to send notification. Status code: ${response.statusCode}');
|
||||
print('❌ Failed to send notification. Code: ${response.statusCode}');
|
||||
print('Error Body: ${response.body}');
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('❌ An error occurred while sending notification: $e');
|
||||
print('❌ Error sending notification: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user