findParentOfPage method
Finds the parent page of the provided page.
Does a tree breadth first search to find the parent of the page. This is used to be able to navigate in the page hierarchy.
Implementation
Page? findParentOfPage(Page page) {
var queue = Queue<Page?>();
queue.add(root);
while (queue.isNotEmpty) {
var p = queue.removeFirst()!;
if (p.next.where((pageNext) => pageNext.nextPage == page).length == 1) {
return p;
} else {
queue.addAll(p.next.map((n) => n.nextPage));
}
}
return null;
}