of static method

AppRouter of(
  1. BuildContext context, {
  2. bool root = false,
})

Get AppRouter placed on the widget tree.

Setting root to true will get AppRouter at the top level.

ウィジェットツリー上に配置されているAppRouterを取得します。

roottrueにすると最上位にあるAppRouterを取得します。

Implementation

static AppRouter of(BuildContext context, {bool root = false}) {
  final navigator = Navigator.of(context, rootNavigator: root).context;
  final scope = navigator
      .getElementForInheritedWidgetOfExactType<AppRouteScope>()
      ?.widget as AppRouteScope?;
  assert(scope != null, "AppRouter is not found.");
  return scope!.router;
}