Skip to content

Instantly share code, notes, and snippets.

@kitoko552
Created February 5, 2020 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitoko552/e11199ddbb031b3cc89a93ada8390ed0 to your computer and use it in GitHub Desktop.
Save kitoko552/e11199ddbb031b3cc89a93ada8390ed0 to your computer and use it in GitHub Desktop.
static NavigatorState of(
BuildContext context, {
bool rootNavigator = false,
bool nullOk = false,
}) {
final NavigatorState navigator = rootNavigator
? context.rootAncestorStateOfType(const TypeMatcher<NavigatorState>())
: context.ancestorStateOfType(const TypeMatcher<NavigatorState>());
assert(() {
if (navigator == null && !nullOk) {
throw FlutterError(
'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 true;
}());
return navigator;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment