'how to cancel a specific notification in flutter

my app is a reminder app, user will add tasks with time that he chose and he will get a notification. tasks will be added in a Listview.builder and the id will be generated randomly

my problem is how the notification will be canceled if he for example removed the third task.

that's the code for adding and removing the tasks that I made:

class TaskData extends ChangeNotifier{
  List<Task> tasks = [];
  int id = Random().nextInt(1000);


  void addNewTask(String newTaskTile , String date ,){
    tasks.add(Task(name: newTaskTile , date: date ,));
      notifyListeners();

  }


  void deleteTask(Task task){
    NotificationService().cancelNotifications(id);
    tasks.remove(task);
    notifyListeners();
  }

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source