fuse<E> method

List<E> fuse<E>(
  1. E element(
    1. T e
    ), {
  2. E? sepatarorBetweenItems,
  3. E? separatorBetweenLists,
})

Do that:

//Input
final List<Widget> children = [
  [SideBarMenuItem(), SideBarMenuItem, SideBarMenuItem()]
  [SideBarMenuItem(), SideBarMenuItem()]
].fuse<Widget>(
    (item) => SideBarMenuTile(item),
    sepatarorBetweenItems: const Spacer(),
    separatorBetweenLists: const BigSpacer()
  );


//Printing result
print(children);

[
  SideBarMenuItem(),
  const Spacer(),
  SideBarMenuItem(),
  const Spacer(),
  SideBarMenuItem(),
  const BigSpacer(),
  SideBarMenuItem(),
  const Spacer(),
  SideBarMenuItem(),
]

Implementation

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