May 6, 2025
Cross-Platform Setup: Configure FCM for both Android and iOS using Firebase console and platform-specific setup files.
Notification Handling: Use listeners to manage messages in foreground, background, and terminated app states.
Permissions & Initialization: Request permissions and initialize Firebase in
main.dart
to start receiving messages.Advanced Messaging: Use topic subscriptions, data-only messages, and Android notification channels for deeper control.
Security Best Practices: Protect API keys, validate device tokens, and secure endpoints with Firebase Authentication.
Full Engagement Pipeline: FCM enables timely, personalized communication that enhances retention and user experience.
Introduction
Push notifications are crucial for user engagement in modern mobile apps. By integrating firebase cloud messaging (FCM) with your Flutter project, you can send targeted messages, updates, and alerts to users in real time. This tutorial walks through setting up push notifications in Flutter using Firebase Cloud Messaging, covering both basic configuration and handling background messages. You should have a Flutter project ready and access to a Firebase console.
Setting up Firebase Project
Create a Firebase project at https://console.firebase.google.com.
For Android:
• Register your app with the Android package name.
• Downloadgoogle-services.json
and place it inandroid/app/
.
• Add the Firebase Gradle plugin toandroid/build.gradle
:
• Apply the plugin in
android/app/build.gradle
:
For iOS:
• Register your iOS bundle ID.
• DownloadGoogleService-Info.plist
, add it toios/Runner
in Xcode.
• In your Podfile, set platform to iOS 10+ and runpod install
.Enable Firebase Cloud Messaging in the Firebase Console under Project Settings > Cloud Messaging.
Configuring Flutter App
Add dependencies in pubspec.yaml:
Then, initialize Firebase and request notification permissions in your main.dart:
Handling Incoming Notifications
Use stream listeners to handle foreground, background, and terminated states.
• Foreground: onMessage triggers while the app is open.
• Background: _firebaseMessagingBackgroundHandler processes messages when the app is backgrounded.
• Terminated: Use FirebaseMessaging.instance.getInitialMessage() inside initState to catch the message that opened the app.
Advanced Topics and Best Practices
• Topic Subscriptions: Organize users by interests.
• Data-Only Messages: Send silent data payloads for background processing.
• Notification Channels (Android): Define channels in AndroidManifest.xml for importance levels.
• Security: Secure server keys, validate tokens, and use Firebase Authentication to restrict access.
Vibe Studio

Vibe Studio, powered by Steve’s advanced AI agents, is a revolutionary no-code, conversational platform that empowers users to quickly and efficiently create full-stack Flutter applications integrated seamlessly with Firebase backend services. Ideal for solo founders, startups, and agile engineering teams, Vibe Studio allows users to visually manage and deploy Flutter apps, greatly accelerating the development process. The intuitive conversational interface simplifies complex development tasks, making app creation accessible even for non-coders.
Conclusion
Implementing push notifications with firebase cloud messaging in Flutter unlocks powerful engagement tools for your app. You’ve set up your Firebase project, configured FCM in Flutter, and learned to handle messages in all app states. Dive deeper into advanced topics like topic management and data-only payloads to build robust notification strategies.