Flutter Quickstart
This guide walks you through integrating PushEngage push notifications into a Flutter application targeting both Android and iOS. Estimated time: 15 minutes.
After completing this guide, your app will receive push notifications on both platforms. See the Flutter SDK Reference for the full API.
Prerequisites
- Flutter SDK 3.x or higher
- Android Studio (for Android builds) and/or Xcode (for iOS builds)
- Firebase account (create one free) — required for Android
- Apple Developer account with a valid App ID — required for iOS
- APNs certificate or key (create one) — required for iOS
- PushEngage account and App ID (see Get Your App ID)
Step 1 — Install the SDK
Add the dependency to pubspec.yaml:
dependencies:
pushengage_flutter_sdk: ^0.0.2
Then run:
flutter pub get
Step 2 — Android Setup
Firebase Cloud Messaging (FCM)
- Open the Firebase console and sign in.
- Click Add Project (or select an existing one).
- Click the Android icon to add an Android app.
- Enter your app's package name (found in
android/app/build.gradleunderapplicationId). - Download google-services.json and place it at
android/app/google-services.json. - Generate the Service Account JSON: Firebase console → Settings → Service accounts → Generate new private key.
- Retrieve the Sender ID: Firebase console → Settings → Cloud Messaging tab.
Connect to PushEngage Dashboard
- Log in to your PushEngage Dashboard.
- Navigate to Site Settings → Installation → Android SDK tab.
- Enter your Firebase Sender ID and upload the Service Account JSON.
- Click Update and copy the App ID.
Step 3 — iOS Setup
Open your iOS workspace in Xcode:
your_project_name/ios/Runner.xcworkspace
Enable Xcode Capabilities
- Select the root project and choose the Runner target.
- Go to Signing & Capabilities → + Capability → Push Notifications.
- Click + Capability → Background Modes, then check Remote notifications and Background fetch.
Connect iOS to PushEngage Dashboard
- PushEngage Dashboard → Site Settings → Installation → iOS SDK tab.
- Upload your APNs certificate or key.
- Copy the App ID.
Step 4 — Add Notification Service Extension (iOS)
Create the Extension
- In Xcode, go to File → New → Target → Notification Service Extension → Next.
- Name it
PushEngageNotificationServiceExtension→ Finish. Click Cancel when prompted to activate. - Set the new target's Deployment Target to iOS 10 or above.
Configure Podfile
Open ios/Podfile. Add the following at the bottom of the file:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
end
end
end
target 'PushEngageNotificationServiceExtension' do
use_frameworks!
pod 'PushEngage', '0.0.6'
end
Run in your ios/ directory:
pod repo update
pod install
Implement the Extension
Replace the auto-generated NotificationService.swift:
import UserNotifications
import PushEngage
@available(iOSApplicationExtension 10.0, *)
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var request: UNNotificationRequest?
override func didReceive(
_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
) {
self.request = request
self.contentHandler = contentHandler
self.bestAttemptContent = request.content.mutableCopy() as? UNMutableNotificationContent
if let bestContent = bestAttemptContent {
PushEngage.didReceiveNotificationExtensionRequest(request, bestContentHandler: bestContent)
contentHandler(bestContent)
}
}
override func serviceExtensionTimeWillExpire() {
if let contentHandler = contentHandler,
let request = request,
let bestAttemptContent = bestAttemptContent {
guard let content = PushEngage.serviceExtensionTimeWillExpire(
request, content: bestAttemptContent
) else {
contentHandler(bestAttemptContent)
return
}
contentHandler(content)
}
}
}
Step 5 — Add Notification Content Extension (iOS, Optional)
- In Xcode, go to File → New → Target → Notification Content Extension → Next.
- Name it
PushEngageNotificationContentExtension→ Finish. Click Cancel when prompted. - Set Deployment Target to iOS 10 or above.
- Add to
ios/Podfile:
target 'PushEngageNotificationContentExtension' do
use_frameworks!
pod 'PushEngage', '0.0.6'
end
Run pod install in the ios/ directory.
Step 6 — Add App Groups (iOS)
- Select the Runner target in Xcode → Signing & Capabilities → + Capability → App Groups.
- Add a new App Group:
group.com.yourcompany.yourapp. - In
ios/Runner/Info.plist, add:- Key:
PushEngage_App_Group_Key - Value:
group.com.yourcompany.yourapp
- Key:
- In
PushEngageNotificationServiceExtension/Info.plist, add the same key and value. - Select the extension target → enable the same App Group under Signing & Capabilities.
Step 7 — Initialize the SDK
In lib/main.dart:
import 'package:flutter/material.dart';
import 'package:pushengage_flutter_sdk/pushengage_flutter_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void initState() {
super.initState();
_initPushEngage();
}
Future<void> _initPushEngage() async {
await PushEngage.setAppId('YOUR_APP_ID');
// Trigger the system permission prompt; on grant, the SDK auto-subscribes.
await PushEngage.requestNotificationPermission();
}
Widget build(BuildContext context) {
return const MaterialApp(
title: 'My App',
home: HomeScreen(),
);
}
}
For iOS distribution, initialize PushEngage in ios/Runner/AppDelegate.swift:
import Flutter
import UIKit
import PushEngage
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override init() {
super.init()
PushEngage.swizzleInjection(isEnabled: true)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}
GeneratedPluginRegistrant.register(with: self)
PushEngage.setBadgeCount(count: 0)
PushEngage.setNotificationWillShowInForegroundHandler { notification, completion in
if notification.contentAvailable == 1 {
completion(nil)
} else {
completion(notification)
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Replace YOUR_APP_ID with the App ID from Steps 2 or 3.
Step 8 — Send a Test Notification
- Build and run on a physical device (Android or iOS).
- Accept the notification permission prompt.
- In the PushEngage Dashboard → Campaign → Push Broadcasts → Create New Push Broadcast → send a test.
Troubleshooting
Android: notifications not received
Verify google-services.json is at android/app/google-services.json and that the Sender ID in the PushEngage Dashboard matches Firebase.
iOS: build sandboxing error
In Xcode → Build Settings → set User Script Sandboxing to No.