makeAsync<T> method
Instantiates an instance of T
, asynchronously.
It is similar to make, but resolves an injection of either
Future<T>
or T
.
Implementation
Future<T>? makeAsync<T>([Type? type]) {
type ??= T;
Type? futureType; //.Future<T>.value(null).runtimeType;
if (T == dynamic) {
try {
futureType = reflector.reflectFutureOf(type).reflectedType;
} on UnsupportedError {
// Ignore this.
}
}
if (has<T>(type)) {
return Future<T>.value(make(type));
} else if (has<Future<T>>()) {
return make<Future<T>>();
} else if (futureType != null) {
return make(futureType);
} else {
throw ReflectionException('No injection for Future<$type> or $type was found.');
}
}