diff --git a/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/app/initialization/firebase_messaging_callbacks.dart b/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/app/initialization/firebase_messaging_callbacks.dart index a11bc6c27..a74904de7 100644 --- a/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/app/initialization/firebase_messaging_callbacks.dart +++ b/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/app/initialization/firebase_messaging_callbacks.dart @@ -10,11 +10,12 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../../common_blocs/push_notifications_bloc.dart'; +import '../../common_services/push_notifications_service.dart'; import '../../models/notification_model.dart'; import '../../utils/local_notifications.dart'; /// Callback executed once the app receives a FCM message while in foreground -void onForegroundMessage(BuildContext context, RemoteMessage message) { +void onForegroundMessage(BuildContext context, RemoteMessage message) async { log('Foreground Message received!'); final notification = message.notification; @@ -26,11 +27,17 @@ void onForegroundMessage(BuildContext context, RemoteMessage message) { // Present the foreground notification on Android only // https://firebase.flutter.dev/docs/messaging/notifications/#application-in-foreground if (!kIsWeb && androidNotification != null) { - showLocalNotification( - id: notification.hashCode, - title: title, - content: body, - ); + final notificationsEnabled = await context + .read() + .areNotificationsEnabled(); + + if (notificationsEnabled) { + await showLocalNotification( + id: notification.hashCode, + title: title, + content: body, + ); + } } else if (kIsWeb) { // TODO: Implement your own logic of presenting notifications on web log('Web notification received: '); diff --git a/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/utils/local_notifications.dart b/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/utils/local_notifications.dart index 75d38a222..bdc73681d 100644 --- a/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/utils/local_notifications.dart +++ b/packages/rx_bloc_cli/mason_templates/bricks/rx_bloc_base/__brick__/lib/base/utils/local_notifications.dart @@ -51,7 +51,7 @@ Future showLocalNotification({ _maxImportanceChannel.id, _maxImportanceChannel.name, channelDescription: _maxImportanceChannel.description, - icon: icon ?? 'app_icon', // To use your own custom icon for foreground + icon: icon ?? 'mipmap/ic_launcher', // To use your own custom icon for foreground // notifications, replace the png file in `android/src/main/res/drawable` ), iOS: const DarwinNotificationDetails(