Skip to content

Add alternateWith extension method on Iterable #628

@alexeyinkin

Description

@alexeyinkin

There is a repeating feature request in Flutter to add separators for children of Row and Column:
flutter/flutter#16957
flutter/flutter#18917
flutter/flutter#55378
flutter/flutter#95263
flutter/flutter#95521

At its highest it got 117 thumbs-ups.
But it is declined over and over again because it can be solved outside of the framework with a few lines of code:

Iterable<T> alternateWith(Iterable<T> items, T separator) {
  return items
      .expand((item) sync* { yield separator; yield item; })
      .skip(1);
}

Can we add it to this package as an extension on Iterable? One could then do:

Column(
  children: <Widget>[
    Widget1(),
    Widget2(),
  ].alternateWith(separator).toList(),
),

One could easily make another package with this, as there are many. Yet they are unknown and may be poorly maintained. This package is widely used, endorsed, and can be referred to in Flutter docs thus ending the recurrance of the feature request or speeding up the debate should it occur again.

I can do it myself if approved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions