Home > database >  Flutter awesome notification click open specific page
Flutter awesome notification click open specific page

Time:03-26

I am using Flutter awesome notifications. When the notification is clicked when the application is closed, I want to direct it to a special page within the application. What is the easiest way for me to do this?

CodePudding user response:

To do this, firstly you need to initialize AwesomeNotifications before runApp and then simply put a listner to listen to the notification click:

Initialize:

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
    );

Listen:

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

you can put that lister in the initState of your splash screen or something before navigating to Home Screen of the app.

  • Related