getDryBaseline method

double? getDryBaseline(
  1. covariant BoxConstraints constraints,
  2. TextBaseline baseline

Returns the distance from the top of the box to the first baseline of the box's contents for the given constraints, or null if this RenderBox does not have any baselines.

This method calls computeDryBaseline under the hood and caches the result. RenderBox subclasses typically don't overridden getDryBaseline. Instead, consider overriding computeDryBaseline such that it returns a baseline location that is consistent with getDistanceToActualBaseline. See the documentation for the computeDryBaseline method for more details.

This method is usually called by the computeDryBaseline or the computeDryLayout implementation of a parent RenderBox to get the baseline location of a RenderBox child. Unlike getDistanceToBaseline, this method takes a BoxConstraints as an argument and computes the baseline location as if the RenderBox was laid out by the parent using that BoxConstraints.

The "dry" in the method name means this method, like getDryLayout, has no observable side effects when called, as opposed to "wet" layout methods such as performLayout (which changes this RenderBox's size, and the offsets of its children if any). Since this method does not depend on the current layout, unlike getDistanceToBaseline, it's ok to call this method when this RenderBox's layout is outdated.

Similar to the intrinsic width/height and getDryLayout, calling this function in performLayout is expensive, as it can result in O(N^2) layout performance, where N is the number of render objects in the render subtree. Typically this method should be only called by the parent RenderBox's computeDryBaseline or computeDryLayout implementation.


double? getDryBaseline(covariant BoxConstraints constraints, TextBaseline baseline) {
  final double? baselineOffset = _computeIntrinsics(_CachedLayoutCalculation.baseline, (constraints, baseline), _computeDryBaseline).offset;
  // This assert makes sure computeDryBaseline always gets called in debug mode,
  // in case the computeDryBaseline implementation invokes debugCannotComputeDryLayout.
  assert(baselineOffset == computeDryBaseline(constraints, baseline));
  return baselineOffset;