of static method

Returns the NavigatorState of the nearest Navigator ancestor.

Implementation

static NavigatorState of(BuildContext context) {
  final scope = context.findAncestorWidgetOfExactType<_NavigatorScope>();
  if (scope == null) {
    throw RadartuiError(
      '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 scope.navigator;
}