How to remove specific items from a list?

FlutterDart

Flutter 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDenis RamdanView Question on Stackoverflow
Solution 1 - FlutterGünter ZöchbauerView Answer on Stackoverflow
Solution 2 - FlutterSuz'l ShresthaView Answer on Stackoverflow
Solution 3 - FlutterCodemakerView Answer on Stackoverflow
Solution 4 - FlutterSilenceCodderView Answer on Stackoverflow
Solution 5 - FluttergsmView Answer on Stackoverflow