selectElementByID<T extends PCanvasElement> method

List<T> selectElementByID<T extends PCanvasElement>(
  1. String? id, {
  2. bool recursive = false,
})

Returns a list of PCanvasElement of type T with a matching id.

Implementation

List<T> selectElementByID<T extends PCanvasElement>(String? id,
    {bool recursive = false}) {
  var elements = this.elements;

  var sel = elements.whereType<T>().where((e) => e.id == id).toList();

  if (!recursive) {
    return sel;
  }

  var subList = elements
      .whereType<PCanvasElementContainer>()
      .expand((e) => e.selectElementByID<T>(id, recursive: true))
      .toList();

  return [...sel, ...subList];
}