getBoxesForSpan method

List<List<TextBox>> getBoxesForSpan(
  1. InlineSpan span, {
  2. double minWidth = 0.0,
  3. double maxWidth = double.infinity,
  4. double minHeight = double.infinity,
  5. double maxHeight = double.infinity,
})

checks for the TextBoxes of this TextPainter and finds their positions in the renderbox.

Becuase every span may paint two or more lines (multiple TextBoxes) the function returns a list of lists of TextBox, each list of TextBoxes is an InlineSpan finding.

Implementation

List<List<TextBox>> getBoxesForSpan(
  InlineSpan span, {
  double minWidth = 0.0,
  double maxWidth = double.infinity,
  double minHeight = double.infinity,
  double maxHeight = double.infinity,
}) {
  final List<List<TextBox>> result = [];

  var renderPar = RenderParagraph(
    this.text!,
    textAlign: textAlign,
    textDirection: textDirection!,
    locale: locale,
    maxLines: maxLines,
    strutStyle: strutStyle,
    textHeightBehavior: textHeightBehavior,
    textScaleFactor: textScaleFactor,
    textWidthBasis: textWidthBasis,
  );

  renderPar.layout(
    BoxConstraints(
      minWidth: minWidth,
      maxWidth: maxWidth,
      minHeight: minHeight,
      maxHeight: maxHeight,
    ),
  );

  var ranges = text!.getTextRanges();

  for (var spanRange in ranges) {
    if (spanRange.span == span) {
      result.add(
        renderPar.getBoxesForSelection(
          TextSelection(
            baseOffset: spanRange.textRange.start,
            extentOffset: spanRange.textRange.end,
          ),
        ),
      );
    }
  }

  return result;
}