Best way to trigger notification in flutter

1,757

If you need to involve multiple people , flutter local notifications isnt for you. It is not build for that.

Share:
1,757
skytect
Author by

skytect

Updated on December 13, 2022

Comments

  • skytect
    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 and flutter_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
      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
      skytect over 4 years
      Wouldn'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
      Renaud Tarnec over 4 years
      Yes, 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
      skytect over 4 years
      My 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
      Renaud Tarnec over 4 years
      I understand... Note however that running every minute corresponds to approx. 43200 invocations a month and the free tier is 125000 invocations a month.
  • skytect
    skytect over 4 years
    Are you able to suggest an alternative solution?
  • רתם שורץ
    רתם שורץ over 4 years
    Firebase is a better option
  • skytect
    skytect over 4 years
    I do appreciate your response, however, if you would like your answer to be accepted, please specify the specific solution in it.