of static method
Get AppRouter placed on the widget tree.
Setting root
to true
will get AppRouter at the top level.
ウィジェットツリー上に配置されているAppRouterを取得します。
root
をtrue
にすると最上位にある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;
}