Push Notifications

Push notifications allow you to send timely and relevant information to a user's phone. From this page, you can enable the push notification feature in your app. After enabling it, you can send the push notification instantly or schedule it to be delivered to the user's device at a specific time.

FlutterFlow uses Firebase Cloud Messaging (A Firebase product) to send push notifications.

General Prerequisites

Before getting started with this section, ensure you have:

iOS Prerequisites

These steps are mandatory if you want to send push notifications to iOS devices:

Add push notifications

Here are the steps to send push notifications:

1. Enabling push notification

Please note, push notifications will not work in these scenarios:

  • Push notifications will not work on an iOS simulator. To test you will need to use a real device.

  • Push notifications will not be delivered to users who are logged out of your app. To send push notifications to users who are not logged in, consider implementing anonymous Firebase login within your app

  • Push notifications will not work if you have the app open on your device.

To enable push notifications:

  1. Click on the Settings and Integrations -> App Settings -> Push Notifications and Enable Push Notifications.

  2. Now, click on the Deploy button. This will create and deploy the Cloud Functions in your Firebase project that are necessary for push notifications to work.

2. Only for iOS: Configuring iOS app

To receive the push notifications in an iOS app, you need to perform the following additional steps.

1. Creating a key

Apple requires developers to create a key for the push notifications inside the Apple Developer Console to verify the push notification's sender.

To create a key:

  1. From your Apple developer account, open the keys section.

  2. Click on the (+) button on the right side of the Keys label.

  3. Enter the Key Name.

  4. Select the Apple Push Notifications service (APNs) from the list below.

  5. Click on Continue and then Register.

  6. Click Download and save the file. It will be needed to add to your Firebase project.

2. Add APNs key to Firebase project

To add APNs key to Firebase project:

  1. Select the Cloud Messaging tab.

  2. Scroll down and find your iOS app under the Apple app configuration section.

  3. Under the APNs Authentication Key section, click on Upload. A popup will appear to upload and enter the key details.

  4. Click on the Browse button to locate and upload the APNs auth key file.

  5. Enter the Key ID. You can find your Key ID in the Apple Developer Center under Certificates, Identifiers & Profiles -> Keys -> Click on Key.

  6. Enter the Team ID. You can find your Team ID in the Apple Member Center under the membership tab.

3. Adding identifier

You must add an Identifier to be able to send the push notifications to the iOS devices after you deploy your app to the app store.

To add an Identifier:

  1. From your Apple developer account open the Identifiers section.

  2. Click on the (+) button on the right side of the Identifiers label.

  3. Select the App IDs and click Continue.

  4. Select the Type App and click Continue.

  5. Enter the Description as ImageNotification.

  6. Enter the Bundle ID as your package name and add .ImageNotification in the end.

  7. Click Continue and then click Register.

4. Enable push notifications in your App ID

Continue with this step only if you have an APP or Bundle ID created in your developer account.

Add the 'Push Notifications' capability to your existing App ID in order to avoid any issues when you re-deploy your app. Here's how you do it:

  1. From your Apple developer account, open the Identifiers section.

  2. Open the identifier with your existing APP ID.

  3. Select Push Notifications from the list.

  4. Click Save.

3. Sending push notifications

Use these steps to create and send push notifications:

  1. Click on the Settings and Integrations -> App Settings -> Push Notifications.

  2. Find the Manually Trigger Notifications section and click on it to expand the section.

  3. In the Notification Title, enter the text that you want to set as a title for notification.

  4. In the Notification Text, enter the content of your notification.

  5. Optional: Click on the Upload Notification Image to set the image that you want to appear in the notification.

  6. Find the Target Audience dropdown. Keep the All option selected if you want to send notifications to both Android and iOS users. You can select Android or iOS if you wish to target OS-specific users.

  7. Enable Deliver With Sound if you wish to.

  8. If you have more than 10K users, you might want to enable the Batch Notifications.

  9. To send push notifications to a specific or few users, enter the user document reference (from the 'users' collection in Firestore) into the User References.

  10. Find the Initial Page dropdown and select a page that you would like to open when a user clicks on the notification.

  11. Click on Send Notification.

  12. To confirm you want to send this notification, a popup will appear. You need to enter the text 'Send Notification' and click on Send Notification again.

Push notifications with data

Sometimes you might want to include additional data with your push notifications, which can then be used to display more detailed information on the page when it's opened through a push notification.

For instance, consider a news app that sends push notifications for breaking news. When the user taps the notification, the additional data could include the news article's title, summary, and image.

Currently we only support sending Firestore document references as data.

To send a push notification with data:

  1. You must have a page that accepts a parameter of type 'DocumentReference'.

  2. Build a notification using the instructions here.

  3. Set the Initial Page to the one that accepts the parameter.

  4. Find the Parameter Data section, copy the document reference from the Firestore, and paste it into the input box below.

  5. Click on Send Notification.

Trigger push notification

You might want to send a push notification when something happens in your app. For example, sending a push notification on a message sent, a push notification on a new appointment booked, a push notification on a price change, etc.

You can send the push notification on such event occurrence by adding the Trigger Push Notification action.

For demonstration purposes, consider an example of sending a push notification to a post creator when someone comments on a post.

Here are the steps:

1. Retrieve the document reference of the user

The document reference of the user is required to send a push notification to a specific user, in this case, it would be the document reference of the post creator.

Normally, you would obtain the user document reference from the Firestore document, where a field like 'created_by' stores the document reference of the post creator. However, for the sake of simplicity, let's assume that we are storing this reference in an app state variable, which looks like this:

If you need to send push notifications to multiple users, consider a scenario where you want to notify all users who liked a post when someone comments on it. You can retrieve the list or array of user document references from the Firestore document or any app state variable within your app. Here's what a list of document references in an app state variable might look like:

Learn more about working with app state variables.

2. Adding the trigger push notification action

Once you figure out how to access the receiver's document reference, you can add the following action.

Trigger Push Notification Action


Push notifications not working; Getting cloud function error: PERMISSION_DENIED: Missing or insufficient permissions

If you encounter an error with push notifications, specifically a cloud function failure due to permission issues, it might be related to your Google Cloud organization's settings. Organizations can disable automatic IAM grants for default service accounts, leading to this error.

To fix this issue, manually grant the Editor role to the default service account used by your project. You can do this by visiting the GCP IAM page and assigning the Editor role to the following service account:

  • For App Engine (Gen 1): {firebase-project-id}@appspot.gserviceaccount.com

  • For Compute Engine (Gen 2): {project-number}-compute@developer.gserviceaccount.com

Also, ensure that these principals (emails) and their roles are present in the permissions tabs in App Engine Default service account, Default compute service account, and firebase-adminsdk. You can do this by visiting the GCP Service Accounts page, clicking on each service account email, and granting access to these principals in the permissions tab.

Below is a sample image for App Engine Default service account.

Last Updated Date: April 9, 2024

Last updated