find<T> static method

T? find<T>(
  1. String key
)

Allows to find an inherited "property".

This method does a lookup every time and is therefore not fast and should only be used in special cases.

Implementation

static T? find<T>(String key) {
  return VComponent.run((vComponent) {
    try {
      final context = VContext(context: vComponent.context, key: _key);
      if (context.hasKey(key)) {
        return context.get(key);
      }

      VNode? parent = vComponent;
      while (parent != null) {
        if (parent.kind == VNodeKind.component) {
          parent = parent as VComponent;
          final parentContext = VContext(context: parent.context, key: _key);
          if (parentContext.hasKey(key)) {
            return parentContext.get(key);
          }
        }

        parent = parent.parent;
      }

      return null;
    } catch (e, s) {
      throw WrappedException(
          "An error occurred while executing the method '$InheritedProperty.find($key)' for component '$vComponent'",
          e,
          s);
    }
  });
}