fix: changes

This commit is contained in:
Ivan Antunes 2024-08-13 11:01:29 -03:00
parent 4a40f6b6b3
commit 6495138588
1 changed files with 22 additions and 16 deletions

View File

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