Created
July 26, 2024 15:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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