How to remove specific items from a list?
FlutterDartFlutter Problem Overview
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..'
)
);
Flutter Solutions
Solution 1 - Flutter
removeWhere
allows to do that:
replytile.removeWhere((item) => item.id == '001')
See also List Dartdoc
Solution 2 - Flutter
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);
Solution 3 - Flutter
//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)
Solution 4 - Flutter
This also works
_listofTaskUI.removeAt(_quantity);
Solution 5 - Flutter
if you have a generic list
List<int> sliderBtnIndex = [];//Your list
sliderBtnIndex.remove(int.tryParse(index)); //remove