of<TWidget extends ScopedWidgetBase> static method
Pass context
to retrieve TWidget
in the ancestor.
If TWidget
does not exist in the ancestor, an error is output.
context
を渡して祖先にあるTWidget
を取り出します。
祖先にTWidget
が存在しない場合はエラーが出力されます。
Implementation
static TWidget of<TWidget extends ScopedWidgetBase>(BuildContext context) {
_ScopedWidgetScope? scope;
if (context.widget is TWidget) {
return context.widget as TWidget;
}
do {
scope = context
.getElementForInheritedWidgetOfExactType<_ScopedWidgetScope>()
?.widget as _ScopedWidgetScope?;
if (scope == null) {
break;
}
if (scope.state.widget.widget is TWidget) {
break;
}
context = scope.state.context;
} while (scope.state.widget.widget is! TWidget);
assert(
scope != null && scope.state.widget.widget is TWidget,
"Could not find $TWidget. Please define $TWidget in the element above.",
);
return scope!.state.widget.widget as TWidget;
}