intersperse static method
Intersperses a divider widget between a list of widgets.
Returns a new list of widgets where a divider widget is inserted between each pair of adjacent widgets in the input list.
The leading
parameter specifies whether to add a divider before
the first widget in the list (default is false
).
The trailing
parameter specifies whether to add a divider after
the last widget in the list (default is false
).
Implementation
static List<Widget> intersperse(
List<Widget> widgets,
Widget divider, {
bool leading = false,
bool trailing = false,
}) {
if (widgets.isNullOrEmpty) return [];
return [
if (leading) divider,
...widgets
.take(widgets.length - 1)
.map((child) => [child, divider])
.expand((element) => element),
widgets.last,
if (trailing) divider,
];
}