replaceRange() functionTo update List elements, you can use the replaceRange() function from the dart:core library’s List class.
The replaceRange() method replaces the value of the element(s) within the provided range.
List.replaceRange(int start_index, int end_index, Iterable <items>)
start_index: An integer value that represents the index position at which the replacement should begin.
end_index: An integer value that represents the index position before which the replacement should terminate.
<items>: An iterable object with the modified values.
This method does not return a value.
The following example demonstrates how to use the replaceRange() method in dart. Click on the “Run” button to execute the code.
void main() {// Creating ListList<String> fruits = ["Orange","Apple", "Mango", "Banana", "Avocado"];// display resultprint('The list item before replacing: ${fruits}');// replace items using replaceRange()fruits.replaceRange(0,3,["Pineapple", "Pawpaw", "Lemon",]);// display updated resultprint('The new list after replacing the items between the range [0-3] is ${fruits}');}