getHeight method

double? getHeight({
  1. double? heightParent,
})

Implementation

double? getHeight({double? heightParent}) {
  if (!hasBoundedHeight) return null;

  double? myHeight;

  // height
  if (height != null) {
    myHeight = height;
  }

  // percentage height based on parent
  else if (heightPercentage != null && heightParent != null) {
    myHeight = ((heightPercentage! / 100) * heightParent);
  }

  // apply model constraints
  if (myHeight != null) {
    // must be greater than minHeight
    var minHeight = getMinHeight(heightParent: heightParent);
    if (minHeight != null && myHeight < minHeight) {
      myHeight = minHeight;
    }

    // must be greater than maxHeight
    var maxHeight = getMaxHeight(heightParent: heightParent);
    if (maxHeight != null && myHeight > maxHeight) {
      myHeight = maxHeight;
    }
  }

  // cannot be negative
  if (myHeight != null && myHeight.isNegative) {
    myHeight = 0;
  }

  return myHeight;
}