Flutter Remove list item

风流意气都作罢 提交于 2020-12-01 08:19:00

问题


I have a question in my flutter dart script, this my script:

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.."
    )
);

My question is: how to remove items on List<ReplyTile> with id = 001.. ?

Thanks in advance


回答1:


removeWhere allows to do that:

replytile.removeWhere((item) => item.id == '001')

See also List Dartdoc




回答2:


In your case this works:

replytile.removeWhere((item) => item.id == '001');

For list with specific datatype such as int, remove also works.Eg:

List id = [1,2,3];
id.remove(1);



回答3:


This also works

_listofTaskUI.removeAt(_quantity);


来源:https://stackoverflow.com/questions/52778601/flutter-remove-list-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!