A Step-By-Step Guide to Integrate Push Notification with FCM in Flutter
Notifications are key nowadays for any mobile app. New technologies and integrations will be challenging at times. It becomes trickier to integrate and resolve all issues when the project deadline is tight.
When we started using Flutter for our app development, we have faced challenges in integrating push notification using Firebase Cloud Messaging. We were very close, still we were missing one configuration. It took time to figure out the missing configuration. So, we have decided to share the steps we have taken to configure the push notification with FCM and test it out from there.
In this article, we will provide the steps on how to integrate push notifications into your flutter app.
Push Notification Workflow
Push notifications are messages that pop up on a user’s mobile device even when the user is not active on device. It is a reminder of actions to do in a timely manner.
It is a message push from backend to frontend under certain conditions through messaging services providers.
Our app is the front end which receives a notification triggered from our backend service. For our app to be able to receive push notifications, it must be configured and registered with a Push Notification Service Provider either Google Cloud Messaging (CGM) or Firebase Cloud Messaging (FCM). Apple Push Notification service (APNs) is an apple service. The communication between backend to frontend is not straightforward due to security reasons, it has to go through IOS or Android operating system and service.
The following are the key steps to initiate, implement and test push notifications.
1. Register our app with Google and Apple
2. Get the key / certificate
3. Implement code in Flutter
For the integration of Firebase Cloud Messaging, Google’s Flutter team provided the "firebase_messaging" package. Add the package dependency to your project’s "pubspec.yaml" and load it by running flutter pub get.
4. Send and Test Notification Messages
This article has shown you how to set up and running push notifications using FCM and APNS for flutter project. Also, different ways to test the notification to make sure all configuration is right and resolve the issues at the right place.