Push notifications in Flutter look easy…
until you actually try to implement them.
Everything seems fine - until:
Notifications don't show in foreground
Background handlers never trigger
And terminated state? Completely broken.
If you've been there… yeah, same
We've faced all of this while working on a production app, and this guide is the exact setup that finally worked.
First - Understand Notification States (This is where most people go wrong)
Before writing a single line of code, you need to understand this:
👉 Each state behaves differently . And if you treat them the same, things will break.
Basic Setup
1. Add dependencies
// pubspec.yaml
firebase_core : ^4.6.0 firebase_messaging : ^16.1.3 flutter_local_notifications : ^21.0.0
Enter fullscreen mode
Exit fullscreen mode
2. Initialize Firebase
Before using FCM, initialize Firebase when your app starts:
await Firebase . initializeApp ();
Enter fullscreen mode
Exit fullscreen mode
3.…