0

I want to handle notification on tap when app in foreground or background then redirect to specific page, I use audio_service plugin to handle background audio, can this plugin handle it?

irufano
  • 108
  • 1
  • 11

2 Answers2

2

You can listen to notification click events via one of the following streams:

  • (v0.17): AudioService.notificationClickEventStream
  • (v0.18): AudioService.notificationClicked

For example:

AudioService.notificationClicked.listen((clicked) {
  if (clicked) {
    // Navigate to the right page based on your app's state
  }
});
Ryan Heise
  • 2,273
  • 5
  • 14
  • I've used `AudioService.notificationClickEventStream` in version (v0.17). The stream click listen when app on background only, if click notif when app on foreground the stream always listen false. @ryanheise – irufano Jul 06 '21 at 02:30
  • actually solved with version (v0.18). Thanks – irufano Jul 06 '21 at 05:10
1

I define the stream in main() :

  AudioService.notificationClicked.listen((event) {
    print('--- Cliked ---');
    _navigationService.push(routes: Routes.PLAYER_PAGE);
  });

I used dependency injection for navigation service which it can push to another page without context @BalasubramanianS

irufano
  • 108
  • 1
  • 11