How can i add an entry to a specific index in a list?
You can use insertRange, it will grow the list when adding new elements.
var list = ["1","3","4"];
list.insertRange(0, 1, "0");
list.insertRange(2, 1, "2");
list.forEach((e) => print(e));
You can try it out on the DartBoard here
You can use the insert()
and removeAt()
methods now.
Dart 2
var idx = 3;
list.insert(idx, 'foo');
Depends on whether you want to insert a single item or a bunch of items
- https://api.dartlang.org/stable/2.1.0/dart-core/List/insert.html
- https://api.dartlang.org/stable/2.1.0/dart-core/List/insertAll.html
All available methods https://api.dartlang.org/stable/2.1.0/dart-core/List-class.html#instance-methods