2

I want to remove an item from my list in a ListView.builder but it's saying it's read only.

List<Map> entries = [{'date': '2019-08-10', 'data': 85.0}, {'date': '2019-08-14', 'data': 84.0}];

onPressed: () {
  removeItem(index);
}

void removeItem(index) {
  entries.removeAt(index);
}

Another exception was thrown: Unsupported operation: read-only

This does not work either:

onPressed: () {
  removeItem(date);
}

void removeItem(date) {
  entries.removeWhere((item) => item['date'] == date);
}
Hasen
  • 11,710
  • 23
  • 77
  • 135

1 Answers1

5

I got the solution from this, the link

entries = List.from(entries)..removeAt("theIndexValue");
balaji b r k
  • 65
  • 2
  • 6