Flutter awesome 通知点击打开特定页面

Flutter awesome notification click open specific page

我正在使用 Flutter 很棒的通知。当应用程序关闭时单击通知时,我想将其定向到应用程序中的特殊页面。对我来说最简单的方法是什么?

要做到这一点,首先你需要在runApp之前initializeAwesomeNotifications然后简单地放一个listner来收听通知点击:

初始化:

AwesomeNotifications().initialize(
        'resource://drawable/logo_circle_notification',
        [
          NotificationChannel(
              channelGroupKey: 'normal_channel_group',
              channelKey: 'normal_channel',
              channelName: 'Normal Notifications',
              channelDescription: 'Notification channel for normal notifications',
              defaultColor: const Color(0xFF9D50DD),
              ledColor: Colors.white
          ),
        ],
        channelGroups: [
          NotificationChannelGroup(
              channelGroupkey: 'basic_channel_group',
              channelGroupName: 'Basic group'),
        ],
        debug: true
    );

听:

listenActionStream(){
        AwesomeNotifications().actionStream.listen((receivedAction) {
          var payload = receivedAction.payload;
    
          if(receivedAction.channelKey == 'normal_channel'){
            //do something here
          }
        });
      }

在导航到应用程序的主屏幕之前,您可以将该列表器放在初始屏幕的 initState 或其他内容中。