withDividerInBetween method
withDividerInBetween Returns a new list with dividers between each widget.
The divider's color, height, thickness, indent, and endIndent can be customized.
If the list is empty, an empty list is returned.
Example:
List<Widget> widgets = [Widget1(), Widget2(), Widget3()];
List<Widget> separatedWidgets = widgets.withDividerInBetween(
color: Colors.grey,
height: 1.0,
thickness: 1.0,
indent: 10.0,
endIndent: 10.0,
);
Implementation
List<Widget> withDividerInBetween({
Color? color,
double? height,
double? thickness,
double? indent,
double? endIndent,
}) {
List<Widget> separatedList = <Widget>[];
final divider = Divider(
color: color,
height: height,
thickness: thickness,
indent: indent,
endIndent: endIndent,
);
for (var i = 0; i < length; i++) {
separatedList.add(this[i]);
ifNotLast(i) ? separatedList.add(divider) : null;
}
return separatedList;
}