verticalConstraints static method

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

Implementation

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

  if (left != null && right != null) {
    maxWidth = maxWidth - (left + right);
  } else if ((left != null && right == null) ||
      (left == null && right != null)) {
    // make sure that the sum of left, right + maxwidth isn't bigger than the screen width.
    final sideDelta = (left ?? 0.0) + (right ?? 0.0) + margin;

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

  if (isUp) {
    if (top != null) {
      minHeight = maxHeight = target.dy - top;
    } else {
      maxHeight = min(maxHeight, target.dy) - margin;
      // TD: clamp minheight
    }
  } else {
    if (bottom != null) {
      minHeight = maxHeight = maxHeight - bottom - target.dy;
    } else {
      maxHeight = min(maxHeight, maxHeight - target.dy) - margin;
      // TD: clamp minheight
    }
  }

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