MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.46k stars 1.4k forks source link

[question] Get context in notificationTap #1604

Closed golane-august closed 2 years ago

golane-august commented 2 years ago

Is there a way to get the current BuildContext when callback for a notification action via notificationTap is called. I mean the function is only called, when the app is brought to foreground, so there should be somewhere a context be available.

Reason is that I want to execute an action, which is provided by a riverpod provider, which is only available from the current context. And also want to display an alert box then. But I don't see a way to hook in the current build process. I saw there is a payload attribute, but this is not enough to access the build context.

Thank you very much! Also searching for a solution, not requiring any static variables, if possible.

MaikuB commented 2 years ago

This is something you need to manage. That actions are triggered for a notification action doesn't mean the context is available for the plugin as a BuildContext is related to a location of a widget so doesn't really have relation to the plugin's functionality

golane-august commented 2 years ago

Ok it seems that the example provides a good workaround with BehaviorSubject