diff --git a/lib/backend/push_notification/pushNotificationService.dart b/lib/backend/push_notification/pushNotificationService.dart index 760ec742..357068be 100644 --- a/lib/backend/push_notification/pushNotificationService.dart +++ b/lib/backend/push_notification/pushNotificationService.dart @@ -125,10 +125,8 @@ class PushNotificationService { onDidReceiveNotificationResponse: (NotificationResponse response) async { if (response.payload != null) { try { - Map message = - validJsonFromString(response.payload!); - var data = - _notificationDetails; // Assuming getOnMessage() now returns the latest RemoteMessage + Map message = validJsonFromString(response.payload!); + var data = _notificationDetails; // Assuming getOnMessage() now returns the latest RemoteMessage _handleNotificationClick(message, extra: data.value); } catch (e) {} } @@ -166,6 +164,7 @@ class PushNotificationService { void _listenToForegroundMessages(BuildContext context) { FirebaseMessaging.onMessage.listen((RemoteMessage message) { + log("Message Foregroud: ${message.data}"); _onMessage.add(message); _notificationDetails.add(message.toMap()['notification']); _showNotification(message); @@ -260,8 +259,7 @@ class PushNotificationService { priority: Priority.high, ); var iOSDetails = DarwinNotificationDetails(); - var generalNotificationDetails = - NotificationDetails(android: androidDetails, iOS: iOSDetails); + var generalNotificationDetails = NotificationDetails(android: androidDetails, iOS: iOSDetails); await _flutterLocalNotificationsPlugin.show( // DateTime.now().millisecondsSinceEpoch % (1 << 31), @@ -279,8 +277,7 @@ class PushNotificationService { case true: // Print the 'data' property // Handle the message data as needed - NotificationHandler().handleMessage(payload, _context.value, - extra: extra.isEmpty ? {} : extra); + NotificationHandler().handleMessage(payload, _context.value, extra: extra.isEmpty ? {} : extra); // Access the 'data' property of 'RemoteMessage' case false: // Handle the message notification as needed @@ -288,19 +285,18 @@ class PushNotificationService { } } - static Future _firebaseMessagingBackgroundHandler( - RemoteMessage message) async {} + static Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { + log("Mensagem firebase: $message"); + } } class NotificationHandler { - void handleMessage(Map message, BuildContext context, - {Map extra = const {}}) { + void handleMessage(Map message, BuildContext context, {Map extra = const {}}) { message.forEach((key, value) {}); switch (message['click_action']) { case 'visit_request': _showVisitRequestDialog(message, context); - break; case '': break; @@ -308,6 +304,7 @@ class NotificationHandler { _showAcessNotificationModal(message, context); break; case 'mensagem': + log("Extra Handle Message: $extra"); _showMessageNotificationDialog(message, context, extra); break; case 'enroll_cond': @@ -355,13 +352,22 @@ class NotificationHandler { ); } - void _showMessageNotificationDialog(Map message, - BuildContext context, Map extra) { + void _showMessageNotificationDialog(Map message, BuildContext context, Map extra) { showDialog( useSafeArea: true, barrierDismissible: true, context: context, builder: (BuildContext context) { + String localId = ''; + try { + localId = jsonDecode(message['local'])['CLI_ID']; + } catch(e, s) { + localId = message['local']['CLI_ID'].toString(); + } + + log("Mensagem: $message"); + log("Extra: $extra"); + return GestureDetector( onTap: () => Navigator.of(context).pop(), child: SizedBox( @@ -375,7 +381,7 @@ class NotificationHandler { width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, child: MessageNotificationModalTemplateComponentWidget( - id: message['local']['CLI_ID'].toString(), + id: localId, from: message['remetente'].toString(), to: message['destinatario'].toString() == 'O' ? 'Morador'