buildHandle method

  1. @override
Widget buildHandle(
  1. BuildContext context,
  2. TextSelectionHandleType type,
  3. double textLineHeight
)
override

Builder for iOS text selection edges.

Implementation

@override
Widget buildHandle(BuildContext context, TextSelectionHandleType type,
    double textLineHeight) {
  // We want a size that's a vertical line the height of the text plus a 18.0
  // padding in every direction that will constitute the selection drag area.
  final Size desiredSize = getHandleSize(textLineHeight);

  final Widget handle = SizedBox.fromSize(
    size: desiredSize,
    child: 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:
      return handle;
    case TextSelectionHandleType.right:
      // Right handle is a vertical mirror of the left.
      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();
  }
}