addAllowedPointer method

  1. @override
void addAllowedPointer (
  1. PointerDownEvent event
)
override

Registers a new pointer that's been checked to be allowed by this gesture recognizer.

Subclasses of GestureRecognizer are supposed to override this method instead of addPointer because addPointer will be called for each pointer being added while addAllowedPointer is only called for pointers that are allowed by this recognizer.

Implementation

@override
void addAllowedPointer(PointerDownEvent event) {
  assert(event != null);
  if (state == GestureRecognizerState.ready) {
    // `_down` must be assigned in this method instead of `handlePrimaryPointer`,
    // because `acceptGesture` might be called before `handlePrimaryPointer`,
    // which relies on `_down` to call `handleTapDown`.
    _down = event;
  }
  if (_down != null) {
    // This happens when this tap gesture has been rejected while the pointer
    // is down (i.e. due to movement), when another allowed pointer is added,
    // in which case all pointers are simply ignored. The `_down` being null
    // means that _reset() has been called, since it is always set at the
    // first allowed down event and will not be cleared except for reset(),
    super.addAllowedPointer(event);
  }
}