useNavigator function
Returns nearest navigator state.
If provided byKey
, will fetch state of a navigator with matching key.
Implementation
NavigatorState useNavigator({Key? byKey}) {
var useNavigatorHook = useHook();
useNavigatorHook ??= setupHook(_UseNavigatorHook(byKey));
if (useNavigatorHook is! _UseNavigatorHook) {
throw Exception(
'Expecting hook of type: $_UseNavigatorHook '
'but got: ${useNavigatorHook.runtimeType}. '
'Please make sure your hooks call order is not dynamic.',
);
}
return useNavigatorHook.state!;
}