of method

Router of (
  1. BuildContext context
)

Retrieves the immediate Router ancestor from the given context.

Use this method when you need to access the delegates in the Router. For example, you need to access the backButtonDispatcher of the parent router to create a ChildBackButtonDispatcher for a nested router. Another use case may be updating the value in routeInformationProvider to navigate to a new route.

Implementation

static Router<dynamic> of(BuildContext context) {
  final _RouterScope scope = context.dependOnInheritedWidgetOfExactType<_RouterScope>();
  assert(scope != null);
  return scope.routerState.widget;
}