Introduction
In Flutter/Dart, we may need to remove items from a List. We'll examine how to do it in this tutorial.
Other useful tips related to operations of lists in Flutter/Dart:
- Filter items in a List in Flutter
- Sort a List in Flutter
- FlatMap a list of lists in Flutter
- Reverse a List in Flutter
- Iterate over List in Flutter
- Find elements in List in Flutter
- Update a list item in Flutter
- Access items from List in Flutter
- Create a list in Flutter
- Combine Lists in Flutter
How to remove items from the List in Flutter
To remove items from a list in Flutter/Dart we can use methods such as: removeAt()
, remove()
, removeWhere()
, removeRange()
or clear()
.
Remove item at a specific index in List using removeAt()
method
The output:
Remove an item from a List by using the remove()
method
The output:
Remove all items that match specific condition using removeWhere()
method
Remove all items whose length is greater then 3:
The output:
Remove all items in the range of a list by using the removeRange()
method
Remove items from index 1 to 3:
The output:
Clear a list using clear()
method
The output:
Conclusion
In this article, we presented how several ways to remove items from a list in Flutter/Dart.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}