Flutter从地图列表中删除项目只读错误

时间:2019-08-14 12:14:45

标签: listview flutter dart

我想从ListView.builder的列表中删除一项,但这是只读的。

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

这也不起作用:

onPressed: () {
  removeItem(date);
}

void removeItem(date) {
  entries.removeWhere((item) => item['date'] == date);
}

1 个答案:

答案 0 :(得分:2)

我从中得到了解决办法,the link

entries = List.from(entries)..removeAt("theIndexValue");