hitTest method Null safety

  1. @override
bool? hitTest(
  1. Offset? position

Called whenever a hit test is being performed on an object that is using this custom paint delegate.

The given point is relative to the same coordinate space as the last paint call.

The default behavior is to consider all points to be hits for background painters, and no points to be hits for foreground painters.

Return true if the given position corresponds to a point on the drawn image that should be considered a "hit", false if it corresponds to a point that should be considered outside the painted image, and null to use the default behavior.


bool? hitTest(Offset? position) {
  if (_thumbRect == null) {
    return null;
  if (ignorePointer) {
    return false;

  // The thumb is not able to be hit when transparent.
  if (fadeoutOpacityAnimation.value == 0.0) {
    return false;

  if (!_lastMetricsAreScrollable) {
    return false;

  return _trackRect!.contains(position!);