computeDistanceToActualBaseline method
- TextBaseline baseline
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, if any, or null otherwise.
Do not call this function directly. If you need to know the baseline of a child from an invocation of performLayout or paint, call getDistanceToBaseline.
Subclasses should override this method to supply the distances to their baselines. When implementing this method, there are generally three strategies:
-
For classes that use the ContainerRenderObjectMixin child model, consider mixing in the RenderBoxContainerDefaultsMixin class and using RenderBoxContainerDefaultsMixin.defaultComputeDistanceToFirstActualBaseline.
-
For classes that define a particular baseline themselves, return that value directly.
-
For classes that have a child to which they wish to defer the computation, call getDistanceToActualBaseline on the child (not computeDistanceToActualBaseline, the internal implementation, and not getDistanceToBaseline, the public entry point for this API).
Implementation
@override
double computeDistanceToActualBaseline(TextBaseline baseline) {
assert(!debugNeedsLayout);
assert(constraints.debugAssertIsValid());
_layoutTextWithConstraints(constraints);
// TODO(garyq): Since our metric for ideographic baseline is currently
// inaccurate and the non-alphabetic baselines are based off of the
// alphabetic baseline, we use the alphabetic for now to produce correct
// layouts. We should eventually change this back to pass the `baseline`
// property when the ideographic baseline is properly implemented
// (https://github.com/flutter/flutter/issues/22625).
return _textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic);
}