Local Notifications vs FCM: Which is right?

Viewed 1001

I have a fairly straight forward Flutter app which incorporates some "social" features, such as the ability for users to add other users as friends.

When a friend request is "send", a record is added to the Firebase to represent the (pending) friendship. I would like the user "receiving" the friend request to get a notification.

I've looked up a dozen or more posts on using local notifications and FCM, but all I can find are bare-bones PoC style examples. I'm at a loss to understand which methodology is correct for this situation.

Can FCM somehow listen for changes on the database, so when the friend request record is created, it would then push a notification? Or should the receiving user's app be listening for changes to the friend requests and push a local notification?

I'm at a loss for where to start.

Thanks in advance!

1 Answers

The answer is "You have to make your backend listen for changes on the database and send FCM".

If you are using firestore as your database, you can use cloud functions to listen to the changes made to your database. You can read more about it here: https://firebase.google.com/docs/firestore/extend-with-functions

If you are using a backend of your own, you can make the backend send FCM to a user using the firebase admin sdk for whatever language you are using.

Related