fuse<E> method

List<E> fuse<E>(
  1. E element(
    1. int index,
    2. T e
    ), [
  2. E? separator
])

Do that:

//Input
final List<Widget> children = [
  ProductModel(),
  ProductModel(),
  ProductModel(),
  ProductModel(),
].fuse<Widget>((index, product) {
  return ProductTile(product);
}, const Spacer());


//Printing result
print(children);

[
  ProductTile(),
  const Spacer(),
  ProductTile(),
  const Spacer(),
  ProductTile(),
  const Spacer(),
  ProductTile(),
]

Implementation

List<E> fuse<E>(E Function(int index, T e) element, [E? separator]) {
  final List<E> items = [];
  for (int i = 0; i < length; i++) {
    items.addAll([
      element(i, this[i]),
      if (i != length - 1 && separator != null) separator
    ]);
  }
  return items;
}