computeLineMetrics method

List<LineMetrics> computeLineMetrics()

Returns the full list of LineMetrics that describe in detail the various metrics of each laid out line.

The LineMetrics list is presented in the order of the lines they represent. For example, the first line is in the zeroth index.

LineMetrics contains measurements such as ascent, descent, baseline, and width for the line as a whole, and may be useful for aligning additional widgets to a particular line.

Valid only after layout has been called.


List<ui.LineMetrics> computeLineMetrics() {
  final _TextPainterLayoutCacheWithOffset layout = _layoutCache!;
  final Offset offset = layout.paintOffset;
  if (!offset.dx.isFinite || !offset.dy.isFinite) {
    return const <ui.LineMetrics>[];
  final List<ui.LineMetrics> rawMetrics = layout.lineMetrics;
  return offset ==
    ? rawMetrics
    : metrics) => _shiftLineMetrics(metrics, offset)).toList(growable: false);