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.

See also:


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 || RenderObject.debugCheckingIntrinsics);
  assert(RenderObject.debugCheckingIntrinsics || switch (owner!) {
    PipelineOwner(debugDoingLayout: true) => RenderObject.debugActiveLayout == parent && parent!.debugDoingThisLayout,
    PipelineOwner(debugDoingPaint: true) => RenderObject.debugActivePaint == parent && parent!.debugDoingThisPaint || (RenderObject.debugActivePaint == this && debugDoingThisPaint),
    PipelineOwner() => false,
  final double? result;
  try {
    result = getDistanceToActualBaseline(baseline);
  } finally {
  if (result == null && !onlyReal) {
    return size.height;
  return result;