How to read received notifications in flutter

3,212

For Android devices, you can use the Notification package. For iOS I'm afraid there's no solution yet.

void onData(NotificationEvent event) => print(event.toString());
Share:
3,212
The Tahaan
Author by

The Tahaan

My feet on a mountain, I am alive.

Updated on December 12, 2022

Comments

  • The Tahaan
    The Tahaan over 1 year

    I know the flutter_local_notifications_plugin allows an app to display notifications.

    I want to access the data of notifications that is received, regardless of whether the app is running in the foreground, in the background, or not running.

    Essentially the app needs to
    - Add that notification to a persistent storage, and
    - Depending on the notification, make a call to an API (eg an HTTP GET), and
    - Depending on user preference settings, display a local notification

    Note the question is not about the detail of implementing these three things as those would each be worthy of a whole article. But how to "receive" these events in each of the three possible app states, on both Android and iOS?

    Broadly I expect some kind of broadcast receiver would need to be registered and a call-back needs to be created for when the event is triggered. I imagine this callbackmay want to be in a special Isolate perhaps since it can't depend on the app being in any particular state.