toList method

List<To> toList({
  1. bool includeThis = true,
  2. bool where(
    1. To path
    )?,
  3. Comparator<To>? sortBy,
})

tree to list /a

  • /a/1
  • /a/2

a.toList(includeThis:true) => /a,/a/1,/a/2

Implementation

List<To> toList({
  bool includeThis = true,
  bool Function(To path)? where,
  Comparator<To>? sortBy,
}) {
  where = where ?? (e) => true;
  if (!where(this)) {
    return [];
  }
  List<To> sorted = List.from(children);
  if (sortBy != null) {
    sorted.sort(sortBy);
  }

  var flatChildren = sorted.expand((child) {
    return child.toList(includeThis: true, where: where, sortBy: sortBy);
  }).toList();
  return includeThis ? [this, ...flatChildren] : flatChildren;
}