List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection)

Returns the global coordinates of the endpoints of the given selection.

If the selection is collapsed (and therefore occupies a single point), the returned list is of length one. Otherwise, the selection is not collapsed and the returned list is of length two. In this case, however, the two points might actually be co-located (e.g., because of a bidirectional selection that contains some text but whose ends meet in the middle).

Source

List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection) {
  // TODO(mpcomplete): We should be more disciplined about when we dirty the
  // layout state of the text painter so that we can know that the layout is
  // clean at this point.
  _textPainter.layout(maxWidth: _maxContentWidth);

  Offset offset = _paintOffset;

  if (selection.isCollapsed) {
    // TODO(mpcomplete): This doesn't work well at an RTL/LTR boundary.
    Offset caretOffset = _textPainter.getOffsetForCaret(selection.extent, _caretPrototype);
    Point start = new Point(0.0, _preferredLineHeight) + caretOffset + offset;
    return <TextSelectionPoint>[new TextSelectionPoint(localToGlobal(start), null)];
  } else {
    List<ui.TextBox> boxes = _textPainter.getBoxesForSelection(selection);
    Point start = new Point(boxes.first.start, boxes.first.bottom) + offset;
    Point end = new Point(boxes.last.end, boxes.last.bottom) + offset;
    return <TextSelectionPoint>[
      new TextSelectionPoint(localToGlobal(start), boxes.first.direction),
      new TextSelectionPoint(localToGlobal(end), boxes.last.direction),
    ];
  }
}