of static method

AdvancedNavigatorState of(
  1. BuildContext context, {
  2. bool rootNavigator = false,
  3. int skip = 0,
  4. String? tag,
})

The router delegate from the closest instance of this class that encloses the given context.

Typical usage is as follows:

AdvancedNavigator.of(context)
  ..pop()
  ..pop()
  ..pushNamed('/settings');

The skip argument denominates the number of instances to be skipped when searching up the widget tree for an instance of AdvancedNavigator.

With the tag argument specified, only navigators with a matching tag will be considered. Should multiple navigators carry a matching tag, the closest instance after skipping skip instances will be returned.

If rootNavigator is set to true, both skip and tag are ignored and the state from the furthest instance of this class is given instead. Useful for pushing contents above all subsequent instances of AdvancedNavigator.

If there is no mathcing AdvancedNavigator in the give context, this function will throw a FlutterError in debug mode, and an exception in release mode.

Implementation

static AdvancedNavigatorState of(
  BuildContext context, {
  bool rootNavigator = false,
  int skip = 0,
  String? tag,
}) {
  var navigator = AdvancedNavigator.maybeOf(
    context,
    rootNavigator: rootNavigator,
    skip: skip,
    tag: tag,
  );
  assert(() {
    if (navigator == null) {
      throw FlutterError(
          'AdvancedNavigator operation requested with a context that does not include an AdvancedNavigator.\n'
          'The context used to push or pop routes from the AdvancedNavigator must be that of a '
          'widget that is a descendant of a Navigator widget.');
    }
    return true;
  }());
  return navigator!;
}