performBoxLayout method

  1. @override
void performBoxLayout(
  1. BoxConstraints constraints
)
override

Perform layout with typed box constraints

Subclasses override this instead of performLayout. The default implementation sizes to the maxima, treating an unbounded axis as the corresponding lower bound.

Implementation

@override
void performBoxLayout(BoxConstraints constraints) {
  final natural = _naturalSize(_metrics);
  var desiredWidth = _width;
  var desiredHeight = _height;
  if (desiredWidth == null && desiredHeight == null) {
    desiredWidth = natural.width;
    desiredHeight = natural.height;
  } else if (desiredWidth == null) {
    desiredWidth = natural.height == 0
        ? 0
        : math.max(
            1,
            (natural.width * desiredHeight! / natural.height).round(),
          );
  } else {
    desiredHeight ??= natural.width == 0
        ? 0
        : math.max(
            1,
            (natural.height * desiredWidth / natural.width).round(),
          );
  }
  size = Size(
    constraints.constrainWidth(desiredWidth),
    constraints.constrainHeight(desiredHeight ?? natural.height),
  );
}