service 2-5-26-2

This commit is contained in:
Hamza-Ayed
2026-05-02 18:36:59 +03:00
parent 255724418c
commit 98846b8158
14 changed files with 912 additions and 534 deletions

View File

@@ -6,6 +6,17 @@ import '../../constant/box_name.dart';
import '../../main.dart';
import '../../print.dart';
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
Log.print("Handling a background message: ${message.messageId}");
if (message.data.isNotEmpty && message.notification != null) {
// في وضع الخلفية، يفضل إرسال إشعار محلي أو تحديث البيانات الصامتة
}
}
class FirebaseMessagesController extends GetxController {
final fcmToken = FirebaseMessaging.instance;
@@ -60,24 +71,18 @@ class FirebaseMessagesController extends GetxController {
});
// 🔹 الاشتراك في topic
await fcmToken.subscribeToTopic("service"); // أو "users" حسب نوع المستخدم
print("Subscribed to 'service' topic ✅");
Log.print("Subscribed to 'service' topic ✅");
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// If the app is in the background or terminated, show a system tray message
RemoteNotification? notification = message.notification;
AndroidNotification? android = notification?.android;
// if (notification != null && android != null) {
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
});
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {
// Handle background message
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
});
// استخدام الدالة العامة للهاندلر في الخلفية
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);