buildHandle method

  1. @override
Widget buildHandle(
  1. BuildContext context,
  2. TextSelectionHandleType type,
  3. double textLineHeight,
  4. [VoidCallback? onTap]
)
override

Builder for iOS text selection edges.

Implementation

@override
Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap]) {
  // iOS selection handles do not respond to taps.
  final Size desiredSize;
  final Widget handle;

  final Widget customPaint = CustomPaint(
    painter: _TextSelectionHandlePainter(CupertinoTheme.of(context).primaryColor),
  );

  // [buildHandle]'s widget is positioned at the selection cursor's bottom
  // baseline. We transform the handle such that the SizedBox is superimposed
  // on top of the text selection endpoints.
  switch (type) {
    case TextSelectionHandleType.left:
      desiredSize = getHandleSize(textLineHeight);
      handle = SizedBox.fromSize(
        size: desiredSize,
        child: customPaint,
      );
      return handle;
    case TextSelectionHandleType.right:
      desiredSize = getHandleSize(textLineHeight);
      handle = SizedBox.fromSize(
        size: desiredSize,
        child: customPaint,
      );
      return Transform(
        transform: Matrix4.identity()
          ..translate(desiredSize.width / 2, desiredSize.height / 2)
          ..rotateZ(math.pi)
          ..translate(-desiredSize.width / 2, -desiredSize.height / 2),
        child: handle,
      );
    // iOS doesn't draw anything for collapsed selections.
    case TextSelectionHandleType.collapsed:
      return const SizedBox.shrink();
  }
}