buildHandle method

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

Builder for material-style text selection handles.

Implementation

@override
Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textHeight, [VoidCallback? onTap]) {
  final ThemeData theme = Theme.of(context);
  final Color handleColor = TextSelectionTheme.of(context).selectionHandleColor ?? theme.colorScheme.primary;
  final Widget handle = SizedBox(
    width: _kHandleSize,
    height: _kHandleSize,
    child: CustomPaint(
      painter: _TextSelectionHandlePainter(
        color: handleColor,
      ),
      child: GestureDetector(
        onTap: onTap,
        behavior: HitTestBehavior.translucent,
      ),
    ),
  );

  // [handle] is a circle, with a rectangle in the top left quadrant of that
  // circle (an onion pointing to 10:30). We rotate [handle] to point
  // straight up or up-right depending on the handle type.
  switch (type) {
    case TextSelectionHandleType.left: // points up-right
      return Transform.rotate(
        angle: math.pi / 2.0,
        child: handle,
      );
    case TextSelectionHandleType.right: // points up-left
      return handle;
    case TextSelectionHandleType.collapsed: // points up
      return Transform.rotate(
        angle: math.pi / 4.0,
        child: handle,
      );
  }
}