I am sending push notifications using Flutter's firebase_messaging package and I send them in the firebase console. When the app is in the background or when it is closed, I am receiving the notifications, however, when the app is in the foreground it is not working. Please tell me if I need to integrate Javascript to make this feature work, and please reference a resource that I can use in order to figure out how I can integrate Javascript with fcm as I haven't found a way to do this with flutter.
-
The Firebase Console is used to send notifications messages. When your app is not in the foreground these messages are handled by the system, and displayed to the user. When the app is in the background, these notifications messages are delivered to `onMessageReceived` (or the equivalent for iOS/web). For more on this, see https://firebase.google.com/docs/cloud-messaging/concept-options#notifications and https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase – Frank van Puffelen Aug 04 '18 at 03:24
-
I found solution on- https://github.com/nitishk72/firebase_messaging_flutter – Nikhat Shaikh Feb 21 '20 at 05:34
2 Answers
I figured out that someone can use the flutter local notifications plugin so that when the push notification is sent and the app is on the foreground, normally no notification would be delivered to the system tray, but using the flutter local notifications plugin, it would be possible to send a local notification when the app is on the foreground.

- 618
- 2
- 9
- 22
To Understand better. Have a look into this table.
https://pub.dev/packages/firebase_messaging#receiving-messages
It states that when your Android or iOS Application is in foreground, OnMessage callback is called if you are sending notification payload or data payload as notification body.
You are receiving notifications when your app is in background because, when an app is in background notification is send to system tray and OS (Android or iOS) handle it for you. And your app is launched when you click on notification from system tray.
When your app is in foreground you have to catch notification payload in onMessage and handle it explicitly, you can create local notification in this case.

- 12,483
- 8
- 38
- 42