getHandleAnchor method Null safety

  1. @override
Offset getHandleAnchor(
  1. TextSelectionHandleType type,
  2. double textLineHeight,
  3. [double? startGlyphHeight,
  4. double? endGlyphHeight]
)
override

Gets anchor for cupertino-style text selection handles.

See TextSelectionControls.getHandleAnchor.

Implementation

@override
Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight, [double? startGlyphHeight, double? endGlyphHeight]) {
  startGlyphHeight = startGlyphHeight ?? textLineHeight;
  endGlyphHeight = endGlyphHeight ?? textLineHeight;

  final Size handleSize;

  switch (type) {
    // The circle is at the top for the left handle, and the anchor point is
    // all the way at the bottom of the line.
    case TextSelectionHandleType.left:
      handleSize = getHandleSize(startGlyphHeight);
      return Offset(
        handleSize.width / 2,
        handleSize.height,
      );
    // The right handle is vertically flipped, and the anchor point is near
    // the top of the circle to give slight overlap.
    case TextSelectionHandleType.right:
      handleSize = getHandleSize(endGlyphHeight);
      return Offset(
        handleSize.width / 2,
        handleSize.height - 2 * _kSelectionHandleRadius + _kSelectionHandleOverlap,
      );
    // A collapsed handle anchors itself so that it's centered.
    case TextSelectionHandleType.collapsed:
      handleSize = getHandleSize(textLineHeight);
      return Offset(
        handleSize.width / 2,
        textLineHeight + (handleSize.height - textLineHeight) / 2,
      );
  }
}