dependency<T> method

T dependency<T>({
  1. bool existingInstance = true,
})

Implementation

T dependency<T>({bool existingInstance = true}) {
  final candidateWidget =
      this.getInheritedWidgetOfExactType<ServiceWaiterInherited>();
  final candidateElement =
      this.getElementForInheritedWidgetOfExactType<ServiceWaiterInherited>();
  if (candidateElement == null || candidateWidget == null)
    throw Exception("ServiceWaiterProvider not found");
  try {
    return (candidateElement as _InheritedElementWithDependencies)
        .serviceWaiter!
        .get<T>(existingInstance: existingInstance);
  } on DependencyNotFoundException {
    return candidateWidget.ownerElement.dependency(
      existingInstance: existingInstance,
    );
  }
}