top of page

[Flutter/dart] The method at notification tapping does not work when the app is terminated


Phenomenon

Create a notification using flutter_local_notification. The method when tapping the notification is also registered.

If the app is up (whether foreground or background) when the notification comes, it works as expected.

However, if the app is terminated when the notification arrives, tapping the notification will not result in the registered operation.


Cause and solution

The registered method will disappear when the application is terminated (reference).


Note: from version 4.0 of the plugin, calling initialize will not trigger the onSelectNotification callback when the application was started by tapping on a notification to trigger. Use the getNotificationAppLaunchDetails method that is available in the plugin if you need to handle a notification triggering the launch for an app e.g. change the home route of the app for deep-linking.



As a countermeasure, a method called getNotificationAppLaunchDetails () tells you whether the app was started by a notification tap, so if it starts from a notification tap, you can perform the desired action.


NotificationAppLaunchDetails _lanuchDeatil
=await flutterLocalNotificationsPlugin.launchedFromNotification();

if (_lanuchDeatil!=null){
    if (_lanuchDeatil.didNotificationLaunchApp){
      if (_lanuchDeatil.payload==null){

      }
      else {
        ・・・         
      }
    }
  }
}

If _lanuchDeatil.didNotificationLaunchApp is true, it is started by a notification tap, so perform what you want. At that time, _lanuchDeatil.payload contains the payload passed when creating the notification, so refer to it.

Recent Posts

See All

Comments


category

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page