of static method
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;
}