
- May 22, 2026
- maulik.jadvani@gmail.com
- 0
Flutter Push Notification Setup Using Firebase FCM (Android & iOS)
Learn how to integrate Firebase Cloud Messaging (FCM) in Flutter applications. This complete tutorial covers Android and iOS push notification setup, foreground and background notifications, FCM token generation, and notification click handling.
What is Firebase Cloud Messaging (FCM)?
Firebase Cloud Messaging (FCM) is a free Google service that allows developers to send push notifications to Android, iOS, and web applications.
- Foreground Notifications
- Background Notifications
- Topic Notifications
- Scheduled Notifications
- Push Notification Click Handling
- Real-Time Messaging
Features We Will Implement
Push Notifications
Receive real-time notifications in Flutter apps.
Android & iOS
Configure notifications for both platforms.
FCM Token
Generate and manage device notification tokens.
Foreground Events
Handle notifications while app is open.
Create Firebase Project
- Open Firebase Console
- Click Create Project
- Enter Project Name
- Complete Firebase Setup
Install Required Packages
Add the following packages in your pubspec.yaml file.
dependencies: firebase_core: ^3.6.0 firebase_messaging: ^15.1.3 flutter_local_notifications: ^17.2.3
Install Packages
flutter pub get
Initialize Firebase
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}Android Setup
Add Android App in Firebase
Download google-services.json and place it inside:
android/app/
Update android/build.gradle
classpath 'com.google.gms:google-services:4.4.2'
Update android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
Set Minimum SDK
minSdkVersion 23
iOS Setup
Download GoogleService-Info.plist and place it inside:
ios/Runner/
Enable the following capabilities in Xcode:
- Push Notifications
- Background Modes
- Remote Notifications
pod install after Firebase setup for iOS.Request Notification Permission
import 'package:firebase_messaging/firebase_messaging.dart';
Future<void> requestPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings =
await messaging.requestPermission(
alert: true,
badge: true,
sound: true,
);
print(settings.authorizationStatus);
}Get FCM Token
FCM token is required for sending notifications to a specific device.
Future<void> getToken() async {
String? token =
await FirebaseMessaging.instance.getToken();
print(token);
}Handle Foreground Notifications
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print(message.notification?.title);
print(message.notification?.body);
});Handle Background Notifications
Future<void> firebaseMessagingBackgroundHandler(
RemoteMessage message) async {
await Firebase.initializeApp();
print(message.messageId);
}Register Background Handler
FirebaseMessaging.onBackgroundMessage( firebaseMessagingBackgroundHandler, );
Handle Notification Click
FirebaseMessaging.onMessageOpenedApp.listen(
(RemoteMessage message) {
print('Notification Clicked');
},
);Complete Notification Service Example
class NotificationService {
FirebaseMessaging messaging =
FirebaseMessaging.instance;
Future<void> initialize() async {
await messaging.requestPermission();
String? token = await messaging.getToken();
print(token);
FirebaseMessaging.onMessage.listen((message) {
print(message.notification?.title);
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
print('Notification Clicked');
});
}
}Common Issues & Solutions
| Issue | Solution |
|---|---|
| Notifications not received | Check notification permissions and Firebase initialization |
| iOS notifications not working | Enable Push Notification capability in Xcode |
| FCM token returning null | Delete and regenerate token |
| Background notification issue | Register background handler correctly |
Benefits of Push Notifications
- Increase app engagement
- Improve user retention
- Send real-time updates
- Increase sales and conversions
- Improve communication with users
Conclusion
Firebase Cloud Messaging (FCM) is one of the best solutions for implementing push notifications in Flutter applications. With proper setup, you can send real-time alerts, marketing notifications, and transactional messages efficiently.
Using Flutter with Firebase helps developers build scalable, high-performance mobile applications for Android and iOS.
