getNestingBranch method

T getNestingBranch(
  1. BuildContext context, {
  2. bool inChildNavigator = false,
})

Implementation

T getNestingBranch(
  BuildContext context, {
  bool inChildNavigator = false,
}) {
  if (inChildNavigator) {
    final parentPageNode = _findAncestorPageNode(context);

    if (parentPageNode == null) {
      throw NavigationStackError(
          'Could not find AppPageNode from the current route.\n'
          'Given context Route is not in the pages stack.');
    }

    if (parentPageNode.crossroad == null) {
      throw NavigationStackError(
          'The given context\'s page does not have nested navigation.\n');
    }

    return parentPageNode.crossroad!.activeBranch;
  } else {
    final navState = context.findAncestorStateOfType<NavigatorState>();

    final crossroad = AppPageNodesStackUtil.findCrossroadInActiveStackByKey(
        navState!.widget.key!, rootPageStack);

    if (crossroad == null) {
      throw NavigationStackError(
          'There is no such navigation key in the active stack');
    }

    return crossroad.activeBranch;
  }
}