how to open a certain page using local notification in Flutter? (Not FCM)


no, I am not asking about Firebase Cloud Messaging notification here, but purely using local notification package from here flutter local notification

I want if my user click the notification then it will be directed to a certain page. how to do that ?

currently my code is like this

class LocalNotificationService  {
  late FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin;
  LocalNotificationService._privateConstructor() {

  static final LocalNotificationService _instance = LocalNotificationService._privateConstructor();
  static LocalNotificationService get instance => _instance; // singleton access

  void _init() {
    _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

  Future<void> _initializePlatformSpecifics() async {
    var androidInitializationSettings = AndroidInitializationSettings("app_notification_icon");
    var iOSInitializationSettings = IOSInitializationSettings(
      requestAlertPermission: true,
      requestBadgePermission: true,
      requestSoundPermission: true,
      onDidReceiveLocalNotification: (id, title, body, payload) async {
        // do something if notification is clicked

    final initializationSettings = InitializationSettings(
      android: androidInitializationSettings,
      iOS: iOSInitializationSettings,

    await _flutterLocalNotificationsPlugin.initialize(initializationSettings);

  void showSimpleNotification({
    required String title,
    required String body,
    required NotificationType notificationType,
  }) async {
    var android = _setAndroidNotificationDetails(notificationType);
    var ios = IOSNotificationDetails();

    var notificationDetails = new NotificationDetails(android: android, iOS: ios);

      1, // only need to show one notification in the notification tray, so it is ok if we use the Notification ID



i recommend reading plugin documentation

as per documentation

    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
  const AndroidInitializationSettings initializationSettingsAndroid =
  final IOSInitializationSettings initializationSettingsIOS =
    requestSoundPermission: false,
    requestBadgePermission: false,
    requestAlertPermission: false,
    onDidReceiveLocalNotification: onDidReceiveLocalNotification,
  final MacOSInitializationSettings initializationSettingsMacOS =
          requestAlertPermission: false,
          requestBadgePermission: false,
          requestSoundPermission: false);
  final InitializationSettings initializationSettings = InitializationSettings(
      android: initializationSettingsAndroid,
      iOS: initializationSettingsIOS,
      macOS: initializationSettingsMacOS);
  await flutterLocalNotificationsPlugin.initialize(initializationSettings,
      onSelectNotification: onSelectNotification);
  • you can pass onSelectNotification function which will be called whenever user click on notification

  • from this function u can redirection to particular screen example as below

           Future selectNotification(String payload) async {
             if (payload != null) {
               debugPrint('notification payload: $payload');
             await Navigator.push(
                   MaterialPageRoute<void>(builder: (context) => 

Answered By – kishan vekariya

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *