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.
  return switch (type) {
    TextSelectionHandleType.left => Transform.rotate(angle: math.pi / 2.0, child: handle), // points up-right
    TextSelectionHandleType.right => handle, // points up-left
    TextSelectionHandleType.collapsed => Transform.rotate(angle: math.pi / 4.0, child: handle), // points up
  };
}