Introduction
Push notifications are a cornerstone of modern mobile development, offering a direct channel to engage users. In Flutter apps, Firebase Cloud Messaging (FCM) provides a robust, cross-platform solution for sending and receiving push notifications on iOS and Android. This tutorial walks through the essential steps to implement push notifications using FCM in your Flutter application—from Firebase project setup to testing on real devices.
Setting up Firebase Project
Begin by creating a Firebase project in the Firebase Console. Navigate to Project Settings > Cloud Messaging to confirm that FCM is enabled. Add your Android and iOS apps under Project Settings > General. Download the google-services.json file for Android and place it in android/app/. For iOS, download GoogleService-Info.plist and add it to Runner/Runner in Xcode.
In Android’s build.gradle files, apply the Google Services plugin:
• In android/build.gradle add classpath 'com.google.gms:google-services:4.3.15' under dependencies.
• In android/app/build.gradle, apply com.google.gms.google-services at the bottom.
On iOS, open ios/Podfile and ensure platform target is at least iOS 11. Then run pod install in the ios/ directory. This step configures native FCM libraries for both platforms.
Configuring Flutter for FCM
Add the core Firebase and messaging packages to your pubspec.yaml:
dependencies:
flutter:
sdk: flutter
firebase_core: ^2.8.0
firebase_messaging
Run flutter pub get, then initialize Firebase in main.dart:
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging messaging = FirebaseMessaging.instance;
await messaging.requestPermission();
runApp(MyApp());
}Requesting permissions is crucial on iOS to present notifications. Android handles permissions at install time, but you can declare <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> in AndroidManifest.xml for API 33+.
Handling Foreground and Background Messages
Flutter’s firebase_messaging offers streams and callbacks to process incoming messages. For foreground notifications, use onMessage:
FirebaseMessaging.onMessage.listen((RemoteMessage msg) {
if (msg.notification != null) {
print('Title: ${msg.notification!.title}');
}
}); To handle clicks and background delivery, define a top-level background handler:
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage msg) async {
await Firebase.initializeApp();
}
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); Use onMessageOpenedApp to navigate when a user taps a notification:
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage msg) {
});These callbacks ensure that you catch messages in all app states: foreground, background, and terminated.
Testing and Deployment
Obtain the device token by calling:
String? token = await FirebaseMessaging.instance.getToken();
print('Device Token: $token');Use this token in the Firebase Console’s Cloud Messaging tab to send test notifications. Verify delivery on both iOS and Android devices. For advanced testing, send data-only payloads and inspect the app’s behavior when killed or backgrounded.
Before submitting to the App Store or Google Play, confirm that your iOS build includes the APNs certificate or authentication key in Firebase settings. On Android, ensure you have the correct google-services.json and a valid SHA-1 fingerprint if using secondary services. Once all tests pass, build your release artifacts (flutter build ios / flutter build apk), and follow platform-specific guides to deploy.
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
Integrating FCM into your Flutter mobile development workflow elevates user engagement through timely, targeted notifications. By setting up a Firebase project, configuring the Flutter app, handling messages across all app states, and thoroughly testing, you’ll deliver a reliable push notification experience. Use these patterns as a foundation and explore advanced features like topic subscriptions and analytics-driven campaigns to further refine your strategy.