hasBehavior<T extends Behavior<EntityMixin>> method

bool hasBehavior<T extends Behavior<EntityMixin>>()

Checks if this entity has at least one behavior with the given type.

This will only return true if the behavior with the type T has a completed lifecycle, aka it is fully mounted.

Implementation

bool hasBehavior<T extends Behavior>() {
  try {
    findBehavior<T>();
    return true;
  } catch (e) {
    if (e is StateError && e.message.startsWith('No behavior of type')) {
      return false;
    }
    rethrow;
  }
}