public static NavigatorState Of( BuildContext context, bool rootNavigator = false, bool nullOk = false ) { var navigator = rootNavigator ? context.RootAncestorStateOfType <NavigatorState>() : context.AncestorStateOfType <NavigatorState>(); if (!nullOk && navigator == null) { throw new Exception( "Navigator operation requested with a context that does not include a Navigator.\n" + "The context used to push or pop routes from the Navigator must be that of a " + "widget that is a descendant of a Navigator widget." ); } return(navigator); }