addWithOutOfBandPosition method

bool addWithOutOfBandPosition(
  1. {Offset? paintOffset,
  2. Matrix4? paintTransform,
  3. Matrix4? rawTransform,
  4. required BoxHitTestWithOutOfBandPosition hitTest}
)

Pass-through method for adding a hit test while manually managing the position transformation logic.

The actual hit testing of the child needs to be implemented in the provided hitTest callback. The position needs to be handled by the caller.

The function returns the return value of the hitTest callback.

A paintOffset, paintTransform, or rawTransform should be passed to the method to update the hit test stack.

  • paintOffset has the semantics of the offset passed to addWithPaintOffset.

  • paintTransform has the semantics of the transform passed to addWithPaintTransform, except that it must be invertible; it is the responsibility of the caller to ensure this.

  • rawTransform has the semantics of the transform passed to addWithRawTransform.

Exactly one of these must be non-null.

See also:

  • addWithPaintTransform, which takes a generic paint transform matrix and documents the intended usage of this API in more detail.

Implementation

bool addWithOutOfBandPosition({
  Offset? paintOffset,
  Matrix4? paintTransform,
  Matrix4? rawTransform,
  required BoxHitTestWithOutOfBandPosition hitTest,
}) {
  assert(
    (paintOffset == null && paintTransform == null && rawTransform != null) ||
    (paintOffset == null && paintTransform != null && rawTransform == null) ||
    (paintOffset != null && paintTransform == null && rawTransform == null),
    'Exactly one transform or offset argument must be provided.',
  );
  if (paintOffset != null) {
    pushOffset(-paintOffset);
  } else if (rawTransform != null) {
    pushTransform(rawTransform);
  } else {
    assert(paintTransform != null);
    paintTransform = Matrix4.tryInvert(PointerEvent.removePerspectiveTransform(paintTransform!));
    assert(paintTransform != null, 'paintTransform must be invertible.');
    pushTransform(paintTransform!);
  }
  final bool isHit = hitTest(this);
  popTransform();
  return isHit;
}