close
0

Insert element at the beginning of the list in dart

avatar
asked 13-09-2021

2 Answers


0

Use insert() method of List to add the item, here the index would be 0 to add it in the beginning. Example:

List<String> list = ["B", "C", "D"];
list.insert(0, "A"); // at index 0 we are adding A
// list now becomes ["A", "B", "C", "D"]
avatar
answered 13-09-2021

0

Use

List.insert(index, value);
avatar
answered 13-09-2021