hitTestInteractive method

bool hitTestInteractive(
  1. Offset position,
  2. PointerDeviceKind kind,
  3. {bool forHover = false}
)

Same as hitTest, but includes some padding when the PointerEvent is caused by PointerDeviceKind.touch to make sure that the region isn't too small to be interacted with by the user.

The hit test area for hovering with PointerDeviceKind.mouse over the scrollbar also uses this extra padding. This is to make it easier to interact with the scrollbar by presenting it to the mouse for interaction based on proximity. When forHover is true, the larger hit test area will be used.

Implementation

bool hitTestInteractive(Offset position, PointerDeviceKind kind, { bool forHover = false }) {
  if (_trackRect == null) {
    // We have not computed the scrollbar position yet.
    return false;
  }
  if (ignorePointer) {
    return false;
  }

  if (!_lastMetricsAreScrollable) {
    return false;
  }

  final Rect interactiveRect = _trackRect!;
  final Rect paddedRect = interactiveRect.expandToInclude(
    Rect.fromCircle(center: _thumbRect!.center, radius: _kMinInteractiveSize / 2),
  );

  // The scrollbar is not able to be hit when transparent - except when
  // hovering with a mouse. This should bring the scrollbar into view so the
  // mouse can interact with it.
  if (fadeoutOpacityAnimation.value == 0.0) {
    if (forHover && kind == PointerDeviceKind.mouse) {
      return paddedRect.contains(position);
    }
    return false;
  }

  switch (kind) {
    case PointerDeviceKind.touch:
    case PointerDeviceKind.trackpad:
      return paddedRect.contains(position);
    case PointerDeviceKind.mouse:
    case PointerDeviceKind.stylus:
    case PointerDeviceKind.invertedStylus:
    case PointerDeviceKind.unknown:
      return interactiveRect.contains(position);
  }
}