Best way to trigger notification in flutter
If you need to involve multiple people , flutter local notifications isnt for you. It is not build for that.
skytect
Updated on December 13, 2022Comments
-
skytect over 1 year
My flutter app allows users to schedule events and needs to notify them when the time comes. These events involve multiple users and may be deleted. I am looking for the best way to trigger the notifications.
So far, I have found 2 packages that may be able to achieve this:
firebase_messaging
andflutter_local_notifications
.With
firebase_messaging
, I thought of creating a cloud function that would be triggered when an event was created in firestore, which schedules another cloud function to be run during the event, checking whether the event still exists in firestore, and triggering notifications accordingly. However, I am unsure of whether it is possible to schedule a cloud function from within another.With
flutter_local_notifications
, my issue is that user B may create events involving user A or the event may be deleted whilst user A's app remains terminated. As such, the scheduled notifications for user A have no way of being adjusted accordingly.What do you think is the best approach?
-
Renaud Tarnec over 4 years"However, I am unsure of whether it is possible to schedule a cloud function from within another." -> you can use a Cloud Pub/Sub trigger, see firebase.google.com/docs/functions/pubsub-events. In the first CF you send a Pub/Sub message to a specific topic that will trigger the second CF.
-
skytect over 4 yearsWouldn't Pub/Sub trigger the second CF immediately? I need to schedule the second CF to be triggered at a certain time (eg. 10:00 1/1/19) in the first CF.
-
Renaud Tarnec over 4 yearsYes, Pub/Sub will trigger the second CF immediately. If you want to trigger another CF at a certain (variable) time you could write a doc in a specific collection with the date/time and have a Scheduled CF (firebase.google.com/docs/functions/schedule-functions) that checks regularly if the date/time value of some of the docs of this collection are inferior to current date/time.
-
skytect over 4 yearsMy issue with that is that the CF would need to run every single minute, which I find very inefficient cost-wise, with most of the events probably occurring within a specific few hours of a day.
-
Renaud Tarnec over 4 yearsI understand... Note however that running every minute corresponds to approx. 43200 invocations a month and the free tier is 125000 invocations a month.
-
-
skytect over 4 yearsAre you able to suggest an alternative solution?
-
רתם שורץ over 4 yearsFirebase is a better option
-
skytect over 4 yearsI do appreciate your response, however, if you would like your answer to be accepted, please specify the specific solution in it.