diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index 15303b61..78e1c73b 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -11,17 +11,11 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/storage_util.dart'; -Future onMessageReceived( - Map payload, String? extra, String? handleClick) async { +Future onMessageReceived(Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; final cliUUID = StorageUtil().cliUUID; - answersRequest( - {required BuildContext context, - required String? ref, - required String? task, - required String? response, - required String? id}) async { + answersRequest({required BuildContext context, required String? ref, required String? task, required String? response, required String? id}) async { final ApiCallResponse? respondeSolicitacaoCall; final RespondeSolicitacaoCall callback = PhpGroup.respondeSolicitacaoCall; @@ -62,10 +56,8 @@ Future onMessageReceived( enText: 'Approve Visit', ), FFLocalizations.of(context).getVariableText( - ptText: - 'Você tem certeza que deseja aprovar essa visita?', - enText: - 'Are you sure you want to approve this visit?', + ptText: 'Você tem certeza que deseja aprovar essa visita?', + enText: 'Are you sure you want to approve this visit?', ), () async { await answersRequest( @@ -102,10 +94,8 @@ Future onMessageReceived( enText: 'Block Visit', ), FFLocalizations.of(context).getVariableText( - ptText: - 'Você tem certeza que deseja bloquear essa visita?', - enText: - 'Are you sure you want to block this visit?', + ptText: 'Você tem certeza que deseja bloquear essa visita?', + enText: 'Are you sure you want to block this visit?', ), () async { await answersRequest .call( @@ -147,8 +137,7 @@ Future onMessageReceived( ptText: 'Mensagem', ): payload['mensagem'], }), - imagePath: - 'https://freaccess.com.br/freaccess/getImage.php?cliID=$cliUUID&atividade=getFoto&Documento=${payload['documento'] ?? ''}&tipo=E', + imagePath: 'https://freaccess.com.br/freaccess/getImage.php?cliID=$cliUUID&atividade=getFoto&Documento=${payload['documento'] ?? ''}&tipo=E', statusHashMap: [ { FFLocalizations.of(context).getVariableText( @@ -180,19 +169,16 @@ Future onMessageReceived( return Dialog( backgroundColor: Colors.transparent, child: DetailsComponentWidget( - imagePath: - 'https://freaccess.com.br/freaccess/getImage.php?cliID=$cliUUID&atividade=getFoto&Documento=$id&tipo=$type', + imagePath: 'https://freaccess.com.br/freaccess/getImage.php?cliID=$cliUUID&atividade=getFoto&Documento=$id&tipo=$type', labelsHashMap: Map.from({ FFLocalizations.of(context).getVariableText( enText: 'Name', ptText: 'Nome', - ): payload['PES_NOME'].toString(), + ): payload['PES_NOME'] != null ? payload['PES_NOME'].toString() : payload['USR_NOME'].toString(), FFLocalizations.of(context).getVariableText( enText: 'Type', ptText: 'Tipo', - ): payload['USR_TIPO'].toString() == 'O' - ? 'Morador' - : 'Visitante', + ): payload['USR_TIPO'].toString() == 'O' ? 'Morador' : 'Visitante', FFLocalizations.of(context).getVariableText( enText: 'Access Date', ptText: 'Data de Acesso', @@ -235,11 +221,8 @@ Future onMessageReceived( child: MessageNotificationModalTemplateComponentWidget( id: localId, from: payload['remetente'].toString(), - to: payload['destinatario'].toString() == 'O' - ? 'Morador' - : 'Visitante', - message: - extra.toString().isEmpty ? 'Unknown' : extra.toString(), + to: payload['destinatario'].toString() == 'O' ? 'Morador' : 'Visitante', + message: extra.toString().isEmpty ? 'Unknown' : extra.toString(), ), ), ); @@ -274,16 +257,10 @@ class NotificationService { ledColor: Colors.white, ) ], - channelGroups: [ - NotificationChannelGroup( - channelGroupKey: 'basic_channel_group', - channelGroupName: 'group_1') - ], + channelGroups: [NotificationChannelGroup(channelGroupKey: 'basic_channel_group', channelGroupName: 'group_1')], debug: kDebugMode); - await AwesomeNotifications() - .isNotificationAllowed() - .then((isAllowed) async { + await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async { final bool requestOSnotification = StorageUtil().requestOSnotification; if (requestOSnotification == false) { @@ -295,29 +272,21 @@ class NotificationService { return; }); - await AwesomeNotifications().setListeners( - onActionReceivedMethod: onActionReceivedMethod, - onNotificationCreatedMethod: onNotificationCreatedMethod, - onNotificationDisplayedMethod: onNotificationDisplayedMethod, - onDismissActionReceivedMethod: onDismissActionReceivedMethod); + await AwesomeNotifications().setListeners(onActionReceivedMethod: onActionReceivedMethod, onNotificationCreatedMethod: onNotificationCreatedMethod, onNotificationDisplayedMethod: onNotificationDisplayedMethod, onDismissActionReceivedMethod: onDismissActionReceivedMethod); } - static Future onActionReceivedMethod( - ReceivedAction receivedAction) async { + static Future onActionReceivedMethod(ReceivedAction receivedAction) async { final payload = receivedAction.payload ?? {}; final extra = receivedAction.body; final handleClick = payload['click_action']; onMessageReceived(payload, extra, handleClick); } - static Future onNotificationCreatedMethod( - ReceivedNotification receivedNotification) async {} + static Future onNotificationCreatedMethod(ReceivedNotification receivedNotification) async {} - static Future onNotificationDisplayedMethod( - ReceivedNotification receivedNotification) async {} + static Future onNotificationDisplayedMethod(ReceivedNotification receivedNotification) async {} - static Future onDismissActionReceivedMethod( - ReceivedAction receivedAction) async {} + static Future onDismissActionReceivedMethod(ReceivedAction receivedAction) async {} static Future show({ required final String title, @@ -348,12 +317,6 @@ class NotificationService { badge: 0, ), actionButtons: actionButtons, - schedule: scheduled - ? NotificationInterval( - interval: Duration(seconds: interval!), - timeZone: - await AwesomeNotifications().getLocalTimeZoneIdentifier(), - preciseAlarm: true) - : null); + schedule: scheduled ? NotificationInterval(interval: Duration(seconds: interval!), timeZone: await AwesomeNotifications().getLocalTimeZoneIdentifier(), preciseAlarm: true) : null); } }