getBoxesForSelection method

  1. @override
List<TextBox> getBoxesForSelection(
  1. TextSelection selection
)
override

Returns a list of rects that bound the given selection.

A given selection might have more than one rect if this text painter contains bidirectional text because logically contiguous text might not be visually contiguous.

Valid only after layout

Implementation

@override
List<TextBox> getBoxesForSelection(TextSelection selection) {
  if (!selection.isCollapsed) {
    return <TextBox>[TextBox.fromLTRBD(0, 0, size.width, size.height, TextDirection.ltr)];
  }

  final left = selection.extentOffset == 0 ? 0.0 : size.width;
  final right = selection.extentOffset == 0 ? 0.0 : size.width;
  return <TextBox>[TextBox.fromLTRBD(left, 0, right, size.height, TextDirection.ltr)];
}