withGaps static method

List<Widget> withGaps(
  1. List<Widget> children, {
  2. required double gap,
  3. required Axis axis,
})

Inserts gap between consecutive children along axis.

Implementation

static List<Widget> withGaps(
  List<Widget> children, {
  required double gap,
  required Axis axis,
}) {
  if (children.length <= 1 || gap <= 0) {
    return children;
  }
  final Widget spacer = SizedBox(
    width: axis == Axis.horizontal ? gap : 0,
    height: axis == Axis.vertical ? gap : 0,
  );
  final out = <Widget>[children.first];
  for (var i = 1; i < children.length; i++) {
    out
      ..add(spacer)
      ..add(children[i]);
  }
  return out;
}