Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove specific items from a list?

Tags:

flutter

How to remove items on List<ReplyTile> with id = 001.. ?

final List<ReplyTile> _replytile = <ReplyTile>[];  _replytile.add(     ReplyTile(         member_photo: 'photo',         member_id: '001',         date: '01-01-2018',         member_name: 'Denis',         id: '001',         text: 'hallo..'     ) ); 
like image 631
Denis Ramdan Avatar asked Oct 12 '18 11:10

Denis Ramdan


People also ask

How do you remove certain items from a list in Python?

How to Remove an Element from a List Using the remove() Method in Python. To remove an element from a list using the remove() method, specify the value of that element and pass it as an argument to the method. remove() will search the list to find it and remove it.

How do I remove a specific value from a list index?

You can use the pop() method to remove specific elements of a list. pop() method takes the index value as a parameter and removes the element at the specified index. Therefore, a[2] contains 3 and pop() removes and returns the same as output. You can also use negative index values.


2 Answers

removeWhere allows to do that:

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

See also List Dartdoc

like image 184
Günter Zöchbauer Avatar answered Sep 20 '22 12:09

Günter Zöchbauer


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); 
like image 38
Suz'l Shrestha Avatar answered Sep 20 '22 12:09

Suz'l Shrestha