findCompInParent<C extends Comp<T>> method

C? findCompInParent<C extends Comp<T>>()
inherited

Walks up the hierarchy and returns the nearest ancestor component of type C, if any.

Implementation

C? findCompInParent<C extends Comp<T>>() {
  var current = parent;
  while (current != null && current is IsAnyComponentManagable<T>) {
    final comp = current.get<C>();
    if (comp != null) return comp;
    current = current.parent;
  }
  return null;
}