gap property

double get gap

The gap between components, that will actually be used for positioning. If one or more ExpandedComponents exist among the children, or if mainAxisAlignment is not a member of gapOverridingAlignments, then this getter simplifies to _gap.

Otherwise, returns the value of gap based on the expected behavior of mainAxisAlignment.

Implementation

double get gap {
  // mainAxisAlignment is not an alignment that can override gaps
  // OR
  // There are [ExpandedComponent]s among the children
  if (!gapOverridingAlignments.contains(mainAxisAlignment) ||
      children.query<ExpandedComponent>().isNotEmpty) {
    return _gap;
  }

  final mainAxisVectorIndex = direction.mainAxis.axisIndex;
  final availableSpace = size[mainAxisVectorIndex];
  final unoccupiedSpace = availableSpace - _mainAxisOccupiedSpace;
  final numberOfGaps = switch (mainAxisAlignment) {
    MainAxisAlignment.spaceEvenly => children.length + 1,
    MainAxisAlignment.spaceAround => children.length,
    MainAxisAlignment.spaceBetween => children.length - 1,
    _ =>
      // this should never happen because of
      // the guard at the start of this method.
      throw Exception('Unexpected call to _gapOverride'),
  };
  return unoccupiedSpace / numberOfGaps;
}
set gap (double newGap)

Implementation

set gap(double newGap) {
  _gap = newGap;
  layoutChildren();
}