of<TAdapter extends MasamuneAdapter> static method
By passing context
, the MasamuneAdapter set in MasamuneAdapterScope can be obtained.
If the ancestor does not have MasamuneAdapterScope, an error will occur.
context
を渡すことによりMasamuneAdapterScopeで設定されたMasamuneAdapterを取得することができます。
祖先にMasamuneAdapterScopeがない場合はエラーになります。
Implementation
static TAdapter? of<TAdapter extends MasamuneAdapter>(BuildContext context) {
final scope = context.getElementForInheritedWidgetOfExactType<
_MasamuneAdapterScope<TAdapter>>();
assert(
scope != null,
"MasamuneAdapterScope<${TAdapter.toString()}> is not found. Place [MasamuneAdapterScope<${TAdapter.toString()}>] widget closer to the root.",
);
return (scope?.widget as _MasamuneAdapterScope<TAdapter>?)?.adapter;
}