How can I get the subtypes of an element using the class DartType from the analyzer
package?
for example if the type is List<String>
, I would like to get String
. Also will be useful to get if the type is generic
.
Another more complex example would be Map<String, String>
where I want to get a list of the subtypes, in this case: [String, String]
.
This one is a little tricky - because
DartType
actually itself has some super types - the one that will interest you here isParameterizedType
:I don't know if it's possible to know if the type is generic - after all, it's just a type. But you can check if the type accepts generic parameters, again, using
ClassElement
:Hope that helps!