My objective in here was get the Type
of the generic type passed on the class GenericTypeDummy
. But somehow I can’t achieved that because I keep getting error.
reflector.dart
import 'package:reflectable/reflectable.dart';
class Reflector extends Reflectable {
const Reflector()
: super(
typeCapability,
typeRelationsCapability,
invokingCapability,
newInstanceCapability,
metadataCapability,
declarationsCapability,
reflectedTypeCapability,
superclassQuantifyCapability,
subtypeQuantifyCapability,
instanceInvokeCapability,
);
}
const reflector = Reflector();
this is my GenericTypeDummy class
@reflector
class GenericTypeDummy<T> {}
main.dart
Type getGenericType<T>() {
var mirror = reflector.reflectType(GenericTypeDummy<T>) as ClassMirror;
var typeArguments = mirror.typeArguments;
if (typeArguments.isNotEmpty) {
return typeArguments.first.reflectedType;
}
return dynamic;
}
print(getGenericType<List<int>>);
The error
Another exception was thrown: Reflecting on type 'GenericTypeDummy<List<int>>' without capability