toList method
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;
}