separete method
Do that:
//Input
final output = [
ProductTile(),
ProductTile(),
ProductTile(),
ProductTile(),
].separete(const Spacer());
//Printing result
print(output);
[
ProductTile(),
const Spacer(),
ProductTile(),
const Spacer(),
ProductTile(),
const Spacer(),
ProductTile(),
]
Implementation
List<T> separete(T separator) {
final List<T> items = [];
for (int i = 0; i < length; i++) {
items.addAll([this[i], if (i != length - 1) separator]);
}
return items;
}