Flutter firestore notification on data change

Viewed 1644

Hie,I'm new in flutter and I'm developing a courier app using firebase for database, now I want the app to display notifications when ever a new delivery request is added to the firestore collection, and also when data is changed in the firestore collection, how can I implement that?

1 Answers

If you need the user to be notified even when they're not actively using the app, you'll want to look at Cloud Functions and Cloud Messaging for this. In fact, this is the number one use-case in the documentation for Cloud Functions: Notify users when something interesting happens.

From there:

Developers can use Cloud Functions to keep users engaged and up to date with relevant information about an app. Consider, for example, an app that allows users to follow one another's activities in the app. Each time a user adds themselves as a follower of another user, a write occurs in the Realtime Database. Then this write event could trigger a function to create Firebase Cloud Messaging (FCM) notifications to let the appropriate users know that they have gained new followers.

enter image description here

  1. The function triggers on writes to the Realtime Database path where followers are stored.
  2. The function composes a message to send via FCM.
  3. FCM sends the notification message to the user's device.

To review working code, see Send FCM notifications.

Related