getDistanceToBaseline method

double? getDistanceToBaseline(
  1. TextBaseline baseline,
  2. {bool onlyReal = false}
)

Returns the distance from the y-coordinate of the position of the box to the y-coordinate of the first given baseline in the box's contents.

Used by certain layout models to align adjacent boxes on a common baseline, regardless of padding, font size differences, etc. If there is no baseline, this function returns the distance from the y-coordinate of the position of the box to the y-coordinate of the bottom of the box (i.e., the height of the box) unless the caller passes true for onlyReal, in which case the function returns null.

Only call this function after calling layout on this box. You are only allowed to call this from the parent of this box during that parent's performLayout or paint functions.

When implementing a RenderBox subclass, to override the baseline computation, override computeDistanceToActualBaseline.

Implementation

double? getDistanceToBaseline(TextBaseline baseline, { bool onlyReal = false }) {
  assert(!_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.');
  assert(!debugNeedsLayout);
  assert(() {
    if (owner!.debugDoingLayout) {
      return (RenderObject.debugActiveLayout == parent) && parent!.debugDoingThisLayout;
    }
    if (owner!.debugDoingPaint) {
      return ((RenderObject.debugActivePaint == parent) && parent!.debugDoingThisPaint) ||
             ((RenderObject.debugActivePaint == this) && debugDoingThisPaint);
    }
    return false;
  }());
  assert(_debugSetDoingBaseline(true));
  final double? result;
  try {
    result = getDistanceToActualBaseline(baseline);
  } finally {
    assert(_debugSetDoingBaseline(false));
  }
  if (result == null && !onlyReal) {
    return size.height;
  }
  return result;
}