selectActivePage method

SemanticNode selectActivePage(
  1. SemanticNode classified
)

Picks the active page among multiple SemanticPages. Candidates are the MAXIMAL onstage pages — a page nested inside another (PageView tab, shell branch) is never a route. Offstage scaffolds already classified as SemanticUnknown, so siblings that remain are stacked navigator routes in overlay order: the LAST is the top of the stack, the screen the user sees. Falls back to SceneCompactor.hoistPage when no page exists.

Implementation

SemanticNode selectActivePage(SemanticNode classified) {
  final candidates = <SemanticPage>[];
  void collect(SemanticNode n) {
    if (n is SemanticPage) {
      candidates.add(n);
      return;
    }
    n.children.forEach(collect);
  }

  collect(classified);
  if (candidates.isNotEmpty) return candidates.last;
  return _compactor.hoistPage(classified);
}