onTapDown method Null safety

  1. @protected
void onTapDown(
  1. TapDownDetails details
)
protected">@protected

Handler for TextSelectionGestureDetector.onTapDown.

By default, it forwards the tap to RenderEditable.handleTapDown and sets shouldShowSelectionToolbar to true if the tap was initiated by a finger or stylus.

See also:

Implementation

@protected
void onTapDown(TapDownDetails details) {
  if (!delegate.selectionEnabled) {
    return;
  }
  renderEditable.handleTapDown(details);
  // The selection overlay should only be shown when the user is interacting
  // through a touch screen (via either a finger or a stylus). A mouse shouldn't
  // trigger the selection overlay.
  // For backwards-compatibility, we treat a null kind the same as touch.
  final PointerDeviceKind? kind = details.kind;
  _shouldShowSelectionToolbar = kind == null
    || kind == PointerDeviceKind.touch
    || kind == PointerDeviceKind.stylus;

  // Handle shift + click selection if needed.
  final bool isShiftPressedValid = _isShiftPressed && renderEditable.selection?.baseOffset != null;
  switch (defaultTargetPlatform) {
    case TargetPlatform.android:
    case TargetPlatform.fuchsia:
    case TargetPlatform.iOS:
      // On mobile platforms the selection is set on tap up.
      if (_isShiftTapping) {
        _isShiftTapping = false;
      }
      break;
    case TargetPlatform.macOS:
      // On macOS, a shift-tapped unfocused field expands from 0, not from the
      // previous selection.
      if (isShiftPressedValid) {
        _isShiftTapping = true;
        final TextSelection? fromSelection = renderEditable.hasFocus
            ? null
            : const TextSelection.collapsed(offset: 0);
        _expandSelection(
          details.globalPosition,
          SelectionChangedCause.tap,
          fromSelection,
        );
        return;
      }
      // On macOS, a tap/click places the selection in a precise position.
      // This differs from iOS/iPadOS, where if the gesture is done by a touch
      // then the selection moves to the closest word edge, instead of a
      // precise position.
      renderEditable.selectPosition(cause: SelectionChangedCause.tap);
      break;
    case TargetPlatform.linux:
    case TargetPlatform.windows:
      if (isShiftPressedValid) {
        _isShiftTapping = true;
        _extendSelection(details.globalPosition, SelectionChangedCause.tap);
        return;
      }
      renderEditable.selectPosition(cause: SelectionChangedCause.tap);
      break;
  }
}