findAsync<S> method

Future<S> findAsync<S>({
  1. dynamic key,
  2. String? tag,
})

Asynchronously resolves a dependency of type S or identified by key or tag.

Implementation

Future<S> findAsync<S>({dynamic key, String? tag}) async {
  if (key is LevitStore) {
    final scope = _ScopeProvider.of(_context) ?? Ls.currentScope;
    final result = await key.findAsyncIn(scope, tag: tag);
    if (result is Future) return await result as S;
    return result as S;
  }
  if (key is LevitAsyncStore) {
    final scope = _ScopeProvider.of(_context) ?? Ls.currentScope;
    return await key.findAsyncIn(scope, tag: tag) as S;
  }
  final scope = _ScopeProvider.of(_context);
  if (scope != null) {
    return await scope.findAsync<S>(tag: tag);
  }
  return await Levit.findAsync<S>(tag: tag);
}