If I try to assign a type with generics to a Type variable I get an error, but if I use a runtimeType variable everything works fine.
Type t = List;
//Type t1 = List<int>; // ERROR !!!
Type t2 = new List<int>().runtimeType;
print('$t $t2'); //> List List<int>
Is it a bug or there is something I'm not getting?
Your first line is surprising, but, yes, it works. Class literals have type "Type":
print((List).runtimeType);
--> TypeImpl
print(List is Type);
--> true
The problem with the rest of your snippet is exactly the issue you found on github:
https://github.com/dart-lang/sdk/issues/11923
-- that class literals cannot use generics. You'll have to get an instance and use runtimeType to get the type you want here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With