findParent<T> method Null safety

T? findParent<T>()

Finds the first parent of a given Type

Implementation

T? findParent<T>() {
  if (this.runtimeType == T) {
    return this as T;
  } else {
    if (parent != null) {
      //find recursively
      var result = parent!.findParent<T>();
      if (result != null) {
        return result;
      }
    }
  }
  return null; //not found
}