onSingleTapUp method Null safety

  1. @protected
void onSingleTapUp(
  1. TapUpDetails details
)
protected">@protected

Handler for TextSelectionGestureDetector.onSingleTapUp.

By default, it selects word edge if selection is enabled.

See also:

Implementation

@protected
void onSingleTapUp(TapUpDetails details) {
  if (delegate.selectionEnabled) {
    // Handle shift + click selection if needed.
    final bool isShiftPressedValid = _isShiftPressed && renderEditable.selection?.baseOffset != null;
    switch (defaultTargetPlatform) {
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        // On desktop platforms the selection is set on tap down.
        if (_isShiftTapping) {
          _isShiftTapping = false;
        }
        break;
      case TargetPlatform.android:
      case TargetPlatform.fuchsia:
        if (isShiftPressedValid) {
          _isShiftTapping = true;
          _extendSelection(details.globalPosition, SelectionChangedCause.tap);
          return;
        }
        renderEditable.selectPosition(cause: SelectionChangedCause.tap);
        break;
      case TargetPlatform.iOS:
        if (isShiftPressedValid) {
          // On iOS, a shift-tapped unfocused field expands from 0, not from
          // the previous selection.
          _isShiftTapping = true;
          final TextSelection? fromSelection = renderEditable.hasFocus
              ? null
              : const TextSelection.collapsed(offset: 0);
          _expandSelection(
            details.globalPosition,
            SelectionChangedCause.tap,
            fromSelection,
          );
          return;
        }
        switch (details.kind) {
          case PointerDeviceKind.mouse:
          case PointerDeviceKind.trackpad:
          case PointerDeviceKind.stylus:
          case PointerDeviceKind.invertedStylus:
            // Precise devices should place the cursor at a precise position.
            renderEditable.selectPosition(cause: SelectionChangedCause.tap);
            break;
          case PointerDeviceKind.touch:
          case PointerDeviceKind.unknown:
            // On iOS/iPadOS a touch tap places the cursor at the edge of the word.
            renderEditable.selectWordEdge(cause: SelectionChangedCause.tap);
            break;
        }
        break;
    }
  }
}