getWidestNode function

BaseNode? getWidestNode(
  1. Iterable<BaseNode> siblings
)

Retrieves the widest child from given siblings.

Implementation

BaseNode? getWidestNode(Iterable<BaseNode> siblings) {
  if (siblings.isEmpty) return null;

  return siblings.reduce((a, b) {
    // If one of the siblings has alignment, while the other does not,
    // return the one with alignment.
    if (a.alignment != AlignmentModel.none &&
        b.alignment == AlignmentModel.none) {
      return a;
    }
    if (b.alignment != AlignmentModel.none &&
        a.alignment == AlignmentModel.none) {
      return b;
    }

    // If both siblings have alignment or both do not have alignment, compare
    // their widths.
    return a.outerBoxLocal.width > b.outerBoxLocal.width ? a : b;
  });
}