of static method

AppRef? of(
  1. BuildContext context
)

By passing context, the AppRef set in AppScoped can be obtained.

If the ancestor does not have AppScoped, an error will occur.

contextを渡すことによりAppScopedで設定されたAppRefを取得することができます。

祖先にAppScopedがない場合はエラーになります。

Implementation

static AppRef? of(BuildContext context) {
  final state = context.findRootAncestorStateOfType<_AppScopedState>();
  assert(
    state != null,
    "AppScoped is not found. Place [AppScoped] widget closer to the root.",
  );
  return state?.widget.appRef;
}