find<S extends Object> method

S? find<S extends Object>(
  1. Offset localPosition
)

Search this layer and its subtree for the first annotation of type S under the point described by localPosition.

Returns null if no matching annotations are found.

By default this method calls findAnnotations with onlyFirst: true and returns the annotation of the first result. Prefer overriding findAnnotations instead of this method, because during an annotation search, only findAnnotations is recursively called, while custom behavior in this method is ignored.

About layer annotations

An annotation is an optional object of any type that can be carried with a layer. An annotation can be found at a location as long as the owner layer contains the location and is walked to.

The annotations are searched by first visiting each child recursively, then this layer, resulting in an order from visually front to back. Annotations must meet the given restrictions, such as type and position.

The common way for a value to be found here is by pushing an AnnotatedRegionLayer into the layer tree, or by adding the desired annotation by overriding findAnnotations.

See also:

Implementation

S? find<S extends Object>(Offset localPosition) {
  final AnnotationResult<S> result = AnnotationResult<S>();
  findAnnotations<S>(result, localPosition, onlyFirst: true);
  return result.entries.isEmpty ? null : result.entries.first.annotation;
}