Future initNotification() async { AndroidInitializationSettings initializationSettingsAndroid = const AndroidInitializationSettings('@mipmap/ic_launcher');

var initializeSettingsIos = DarwinInitializationSettings(
    requestAlertPermission: true,
    requestBadgePermission: true,
    requestSoundPermission: true,
    onDidReceiveLocalNotification:
        (int id, String? title, String? body, String? payload) async {});

var initializeSettings = InitializationSettings(
    android: initializationSettingsAndroid, iOS: initializeSettingsIos);

flutterLocalNotificationsPlugin.initialize(
  initializeSettings,
  onDidReceiveNotificationResponse: (notificationResponse) async {
    switch (notificationResponse.notificationResponseType) {
      case NotificationResponseType.selectedNotification:
        if (notificationResponse.payload!
            .startsWith('redirect_to_result|')) {
          // Extract the response data from the payload
          final response = notificationResponse.payload?.split('|')[1];
          navigatorKey.currentState?.pushNamed(RoutesName.result,
              arguments: response.toString());
        }
        break;
      case NotificationResponseType.selectedNotificationAction:
        if (notificationResponse.actionId == notificationCancelId) {
          service.invoke('stopService');
        }
        break;
    }
  },
);

const AndroidNotificationChannel channel = AndroidNotificationChannel(
  notificationChannelId,
  notificationChannelName,
  description: 'This channel is used for important notifications.',
  importance: Importance.high,
);

await flutterLocalNotificationsPlugin
    .resolvePlatformSpecificImplementation<
        AndroidFlutterLocalNotificationsPlugin>()
    ?.createNotificationChannel(channel);

}

I tried many solution, but : Flutter app from the terminated state due to a notification tap is not a typical use case and is challenging because the navigation stack and routing system are not available.Help me fix it

0

There are 0 answers