contains method Null safety

bool contains(
  1. DisplayObject child

Determines whether the specified DisplayObject is a child of this DisplayObjectContainer instance or the instance itself.

The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren, great-grandchildren, and so on each return true.


bool contains(DisplayObject child) {
  DisplayObject? localChild = child;
  while (localChild != null) {
    if (localChild == this) return true;
    localChild = localChild.parent;
  return false;