addInBetween method

List<Widget> addInBetween(
  1. Widget widget
)

Add a widget between each pair of widgets in the list.

The addInBetween extension function is used to insert a specified widget between each pair of widgets in the list. It iterates through the list of widgets and inserts the provided widget between consecutive widgets in the original list. The resulting list contains the original widgets and the added widget at the specified positions.

Parameters:

  • widget: The widget to be inserted between the existing widgets in the list.

Returns: A new list of widgets with the specified widget inserted between each pair of widgets in the original list.

Implementation

List<Widget> addInBetween(Widget widget) {
  final widgets = <Widget>[];
  for (int i = 0; i < length; i++) {
    widgets.add(this[i]);
    if (i < length - 1) {
      widgets.add(widget);
    }
  }
  return widgets;
}