findAnchor method

Future<Anchor?> findAnchor(
  1. String anchorKeyId, {
  2. HelperAlignment? align,
  3. bool isInModal = false,
})

Returns an Anchor wich contains position, size and rect of the widget containing the key.

this requires an anchorKeyId to search within our keys

Implementation

Future<Anchor?> findAnchor(
  String anchorKeyId, {
  HelperAlignment? align,
  bool isInModal = false,
}) async {
  final element = _elementFinder! //
      .searchChildElementByKey(getAnchorKey(anchorKeyId),
          isInModal: isInModal);
  if (element == null || element.bounds == null) {
    debugPrint("anchor not found");
    return null;
  }
  final anchorSize = element.bounds!.size;
  final currentPos = element.offset!;
  if (align != null) {
    return Anchor(
      size: anchorSize,
      offset: currentPos,
      rect: _elementFinder!.getSpaceFromAlignment(align, element),
    );
  }
  return Anchor(
    size: anchorSize,
    offset: currentPos,
    rect: _elementFinder!.getLargestAvailableSpace(element),
  );
}