Skip to content

Instantly share code, notes, and snippets.

@sixtusagbo
Created July 26, 2024 15:06
Show Gist options
  • Save sixtusagbo/45cdf7136dc14398e08dab77087a831f to your computer and use it in GitHub Desktop.
Save sixtusagbo/45cdf7136dc14398e08dab77087a831f to your computer and use it in GitHub Desktop.
Add a widget between each pair of widgets in a list of widgets.
/// Extension on Iterable<Widget> to add a specified widget between each pair of widgets.
extension WidgetIterableExtension on Iterable<Widget> {
List<Widget> addBetween(Widget child) {
final iterator = this.iterator;
final result = <Widget>[];
if (iterator.moveNext()) result.add(iterator.current);
while (iterator.moveNext()) {
result
..add(child)
..add(iterator.current);
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment