import 'package:http/http.dart' as http; import 'dart:convert'; class NotificationService { // استبدل هذا الرابط بالرابط الصحيح لملف PHP على السيرفر الخاص بك static const String _serverUrl = 'https://syria.intaleq.xyz/intaleq/fcm/send_fcm.php'; static Future sendNotification({ required String target, required String title, required String body, String? tone, List? driverList, // <-- [تعديل 1] : إضافة المتغير الجديد bool isTopic = false, }) async { try { final Map payload = { 'target': target, 'title': title, 'body': body, 'isTopic': isTopic, }; // نضيف النغمة فقط إذا لم تكن فارغة if (tone != null) { payload['tone'] = tone; } // <-- [تعديل 2] : نضيف قائمة البيانات بعد تشفيرها إلى JSON if (driverList != null) { payload['driverList'] = jsonEncode(driverList); } final response = await http.post( Uri.parse(_serverUrl), headers: { 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode(payload), ); if (response.statusCode == 200) { print('✅ Notification sent successfully.'); print('Server Response: ${response.body}'); } else { print( '❌ Failed to send notification. Status code: ${response.statusCode}'); print('Server Error: ${response.body}'); } } catch (e) { print('❌ An error occurred while sending notification: $e'); } } }