find<T> static method

T find<T>(
  1. BuildContext context, {
  2. String? tag,
})

Resolves T from the nearest ancestor SintScope in context, falling back to the global container when not overridden in an ancestor scope.

Implementation

static T find<T>(BuildContext context, {String? tag}) {
  if (context is Element) {
    _InheritedSintScope? inherited = context
        .getElementForInheritedWidgetOfExactType<_InheritedSintScope>()
        ?.widget as _InheritedSintScope?;
    while (inherited != null) {
      final match = InjectionExtension.findInScope<T>(
        inherited.container,
        tag: tag,
      );
      if (match != null) return match;
      final parentElement = inherited.parentContext;
      inherited = parentElement
          ?.getElementForInheritedWidgetOfExactType<_InheritedSintScope>()
          ?.widget as _InheritedSintScope?;
    }
    return InjectionExtension.findGlobal<T>(tag: tag);
  }
  return Sint.find<T>(tag: tag);
}