getDistanceToBaseline method
- TextBaseline baseline, {
- 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:
- getDryBaseline, which returns the baseline location of this RenderBox at a certain BoxConstraints.
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 || 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,
});
assert(_debugSetDoingBaseline(true));
final double? result;
try {
result = getDistanceToActualBaseline(baseline);
} finally {
assert(_debugSetDoingBaseline(false));
}
if (result == null && !onlyReal) {
return size.height;
}
return result;
}