In main.dart add code for init Push Express sdk. Replace the default value of 12345-12 with the PULEXPRESS_APP_ID of your application. You can find out your PUSHEXPRESS_APP_ID in the Applications.
void initFirebase() async {
// Initialize firebase app
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Request permissions for push notifications
await FirebaseMessaging.instance.requestPermission();
// get unique token for messaging from firebase messaging
String? token = await FirebaseMessaging.instance.getToken();
if (token != null) {
// initialize package
PushExpressManager().init(
// your application id from https://app.push.express/
'12345-12',
TransportType.fcmData,
transportToken: token,
// set property foreground "true" if you need to get notifications when app is in foreground (IOS only)
foreground: true,
);
}
}
Call initFirebase() in the initState() method in the main.dart file.
Add a background push notification handler to Firebase Cloud Messaging in the main.dart file.
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// initialize firebase app
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// call function from the package to handle notifications,
// and show them properly in background
NotificationManager().handleNotification(message);
}
Register the firebaseMessagingBackgroundHandler background push notification handler in the main() function of the main.dart file.