inherentSize property
Vector2
get
inherentSize
Any positioning done in layoutChildren should not affect the inherentSize. This is because all crossAxisAlignment transformations fall within the largestCrossAxisLength, while mainAxisAlignment is entirely ignored in all cases where inherentSize is needed. This means that inherentSize should be used before layoutChildren.
Implementation
Vector2 get inherentSize {
// Used at multiple points, cache to avoid recalculating each invocation
final positionChildren = this.positionChildren;
final crossAxisVectorIndex = direction.crossAxisVectorIndex;
final mainAxisVectorIndex = direction.mainAxisVectorIndex;
if (positionChildren.isEmpty) {
return Vector2.zero();
}
final largestCrossAxisLength = positionChildren
.map((component) => component.size[crossAxisVectorIndex])
.max;
// This is tricky because it depends on the mainAxisAlignment.
// This should only apply when mainAxisAlignment is start, center, or end.
// spaceAround, spaceBetween, and spaceEvenly requires the size as a
// constraint.
final cumulativeMainAxisLength = ((positionChildren.length - 1) * gap) +
positionChildren
.map((component) => component.size[mainAxisVectorIndex])
.sum;
final out = Vector2.zero();
out[mainAxisVectorIndex] = cumulativeMainAxisLength;
out[crossAxisVectorIndex] = largestCrossAxisLength;
return out;
}