expandAncestors<T> method
Utility method for expanding a route and its ancestors into a list of items.
Each ancestor of this route will be visited, starting from root until
this. The callback will be called for each route, and the result
of the callback will be expanded into the final returned list.
Implementation
List<T> expandAncestors<T>(
Iterable<T> Function(AppRoute ancestor) callback,
) {
final ancestors = <AppRoute>[];
AppRoute? current = this;
while (current != null) {
ancestors.insert(0, current);
if (current is ChildAppRoute) {
current = current.parent;
} else {
current = null;
}
}
return ancestors.expand(callback).toList();
}