addBetween method
Return a new list, adding a separator between the original list items (but not before the first and after the last).
["A", "B", "C"].addBetween("|") = ["A", "|", "B", "|", "C"];
It may be used with widgets:
[Container(), Container()].addBetween(SizedBox());
Implementation
List<T> addBetween(T separator) {
if (length <= 1)
return toList();
//
else {
final List<T> newItems = <T>[];
for (int i = 0; i < length - 1; i++) {
newItems.add(this[i]);
newItems.add(separator);
}
newItems.add(this[length - 1]);
return newItems;
}
}