2

I want to add deleted items in Bin where I can restore or delete permanently. I used things which is listed below. However, I want to add deleted data in deletedList. So, How Can I? So, please help me.

List deletedList = [];
void delete() {
    allCategory.removeWhere((element) => element.isSelected == true);
  }

Thanks in advance.

Parth Patel
  • 105
  • 1
  • 8

2 Answers2

3

You can loop through allCategory list, check if isSelected==true, then first add to deletedList then remove from allCategory list.

  for(int i=0; i<allCategory.length; i++){
    if(allCategory[i].isSelected==true) {
        deletedList.add(allCategory[i]);
        allCategory.removeAt(i);
    }
  }
Amani Saaduddin
  • 288
  • 7
  • 23
2

This will work:

deletedItemList = (allCategory.where((element) => element.isSelected == true)).toList();
allCategory.removeWhere((element) => element.isSelected == true);
Tyler2P
  • 2,324
  • 26
  • 22
  • 31