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 {
if (response.payload != null) {
try {
Map<String, dynamic> message =
validJsonFromString(response.payload!);
var data =
_notificationDetails; // Assuming getOnMessage() now returns the latest RemoteMessage
Map<String, dynamic> 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<void> _firebaseMessagingBackgroundHandler(
RemoteMessage message) async {}
static Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
log("Mensagem firebase: $message");
}
}
class NotificationHandler {
void handleMessage(Map<String, dynamic> message, BuildContext context,
{Map<String, dynamic> extra = const {}}) {
void handleMessage(Map<String, dynamic> message, BuildContext context, {Map<String, dynamic> 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<String, dynamic> message,
BuildContext context, Map<String, dynamic> extra) {
void _showMessageNotificationDialog(Map<String, dynamic> message, BuildContext context, Map<String, dynamic> 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'