of<TAdapter extends MasamuneAdapter> static method

TAdapter? of<TAdapter extends MasamuneAdapter>(
  1. BuildContext context
)

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;
}