of<T extends INuRouter> static method
NuvigatorState<T> ?
of<T extends INuRouter>(
- BuildContext context, {
- bool rootNuvigator = false,
- bool nullOk = false,
Fetches a NuvigatorState from the current BuildContext.
Implementation
static NuvigatorState<T>? of<T extends INuRouter>(
BuildContext context, {
bool rootNuvigator = false,
bool nullOk = false,
}) {
if (rootNuvigator) {
return context.findRootAncestorStateOfType<NuvigatorState<T>>();
} else {
final closestNuvigator =
context.findAncestorStateOfType<NuvigatorState<T>>();
if (closestNuvigator != null) return closestNuvigator;
assert(() {
if (!nullOk) {
throw FlutterError(
'Nuvigator operation requested with a context that does not include a Nuvigator.\n'
'The context used to push or pop routes from the Nuvigator must be that of a '
'widget that is a descendant of a Nuvigator widget.'
'Also check if the provided Router [T] type exists withing a the Nuvigator context.');
}
return true;
}());
return null;
}
}