Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local notification not being shown on android #994

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<PushNotificationsService>()
.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: ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Future<void> 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(
Expand Down