findAnnotations<S extends Object> method

  1. @override
bool findAnnotations<S extends Object>(
  1. AnnotationResult<S> result,
  2. Offset localPosition, {
  3. required bool onlyFirst,
})
override

Searches the subtree for annotations of type S at the location localPosition, then adds the annotation value if applicable.

This method always searches its children, and if any child returns true, the remaining children are skipped. Regardless of what the children return, this method then adds this layer's annotation if all of the following restrictions are met:

  • The target type must be identical to the annotated type T.
  • If size is provided, the target position must be contained within the rectangle formed by size and offset.

This search process respects onlyFirst, meaning that when onlyFirst is true, the search will stop when it finds the first annotation from the children, and the layer's own annotation is checked only when none is given by the children.

The return value is true if any child returns true, or if opaque is true and the layer's annotation is added.

For explanation of layer annotations, parameters and return value, refer to Layer.findAnnotations.

Implementation

@override
bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) {
  bool isAbsorbed = super.findAnnotations(result, localPosition, onlyFirst: onlyFirst);
  if (result.entries.isNotEmpty && onlyFirst) {
    return isAbsorbed;
  }
  if (size != null && !(offset & size!).contains(localPosition)) {
    return isAbsorbed;
  }
  if (T == S) {
    isAbsorbed = isAbsorbed || opaque;
    final Object untypedValue = value;
    final S typedValue = untypedValue as S;
    result.add(AnnotationEntry<S>(
      annotation: typedValue,
      localPosition: localPosition - offset,
    ));
  }
  return isAbsorbed;
}