horizontalConstraints static method

BoxConstraints horizontalConstraints({
  1. required BoxConstraints constraints,
  2. required double? top,
  3. required double? bottom,
  4. required double? right,
  5. required double? left,
  6. required double margin,
  7. required bool isRight,
  8. required Offset target,
})

Implementation

static BoxConstraints horizontalConstraints({
  required BoxConstraints constraints,
  required double? top,
  required double? bottom,
  required double? right,
  required double? left,
  required double margin,
  required bool isRight,
  required Offset target,
}) {
  var maxHeight = constraints.maxHeight;
  var minWidth = constraints.minWidth;
  var maxWidth = constraints.maxWidth;

  if (top != null && bottom != null) {
    maxHeight = maxHeight - (top + bottom);
  } else if ((top != null && bottom == null) ||
      (top == null && bottom != null)) {
    // make sure that the sum of top, bottom + _maxHeight isn't bigger than the screen Height.
    final sideDelta = (top ?? 0.0) + (bottom ?? 0.0) + margin;

    if (maxHeight > maxHeight - sideDelta) {
      maxHeight = maxHeight - sideDelta;
    }
  } else {
    if (maxHeight > maxHeight - 2 * margin) {
      maxHeight = maxHeight - 2 * margin;
    }
  }

  if (isRight) {
    if (right != null) {
      minWidth = maxWidth = maxWidth - right - target.dx;
    } else {
      maxWidth = min(maxWidth, maxWidth - target.dx) - margin;
    }
  } else {
    if (left != null) {
      minWidth = maxWidth = target.dx - left;
    } else {
      maxWidth = min(maxWidth, target.dx) - margin;
    }
  }

  return constraints.copyWith(
    maxHeight: maxHeight,
    minWidth: minWidth,
    maxWidth: maxWidth,
  );
}