typeCode method
type as code, with the import prefix of an enum
Implementation
String typeCode(DartType type, {bool? nullable}) {
bool isNullable =
nullable ?? type.nullabilitySuffix == NullabilitySuffix.question;
String q = isNullable ? '?' : '';
if (type is! InterfaceType) return 'dynamic';
String name = type.element.displayName;
if (type.element is EnumElement) {
return '${_prefix(type.element.library.uri.toString())}.$name$q';
}
if (type.typeArguments.isEmpty) return '$name$q';
String args = <String>[
for (DartType arg in type.typeArguments) typeCode(arg),
].join(', ');
return '$name<$args>$q';
}