Flutter移除清单项目

时间:2018-10-12 11:30:09

标签: dart flutter

我的飞镖脚本中有一个问题,这是我的脚本:

List<ReplyTile> replytile = new List<ReplyTile>();

replytile.add(
    new ReplyTile(
        member_photo: "photo",
        member_id: "001",
        date: "01-01-2018",
        member_name: "Denis",
        id: "001",
        text: "hallo.."
    )
);

我的问题是:如何使用List<ReplyTile>删除id = 001上的项目。?

预先感谢

4 个答案:

答案 0 :(得分:14)

'script'允许这样做:

removeWhere

另请参阅List Dartdoc

答案 1 :(得分:1)

//For removing specific item from a list with the attribute value
replytile.removeWhere((item) => item.id == '001') 

//Remove item by specifying the position of the item in the list
replytile.removeAt(2)   

//Remove last item from the list
replytile.removeLast()

//Remove a range of items from the list
replytile.removeRange(2,5)

答案 2 :(得分:0)

这也有效

_listofTaskUI.removeAt(_quantity);

答案 3 :(得分:0)

如果你有一个通用列表

List<int> sliderBtnIndex = [];//Your list

sliderBtnIndex.remove(int.tryParse(index)); //remove