xxxxxxxxxx
myList.removeWhere((item) => item.id == '001')
myList.clear() // Clear All!
xxxxxxxxxx
List<int> myList = [1, 2, 3, 4, 5];
int itemToRemove = 3;
myList.remove(itemToRemove);
print(myList); // Output: [1, 2, 4, 5]
xxxxxxxxxx
void main() {
List l = [1, 2, 3,4,5,6,7,8,9];
print('The value of list before removing the list element ${l}');
bool res = l.remove(1);
print('The value of list after removing the list element ${l}');
}
xxxxxxxxxx
// A row of fruit
List<String> fruitBowl = ["apple", "banana", "pear", "orange", "banana", "apple"];
// fruitRow = [apple, banana, pear, orange, banana, apple]
// Eat all of the bananas
fruitRow.removeWhere((fruitItem) => fruitItem == "banana");
// fruitRow = [apple, pear, orange, apple]
// Now eat the first apple
fruitRow.remove("apple"); // fruitRow = [pear, orange, apple]
// Now eat the second piece of fruit (index = 1)
fruitRow.removeAt(1); // fruitRow = [pear, apple]