forArrayComponent static method
Returns a ResolvableType representing an array of the specified component type.
This factory method creates a ResolvableType that represents an array (List in Dart) with the specified component type. This is useful for programmatically creating array types when you know the element type.
Parameters:
componentType
: The ResolvableType representing the array element type
Returns:
- ResolvableType representing an array of the component type
Example:
final stringType = ResolvableType.forClass(String);
final userType = ResolvableType.forClass(User);
final stringArrayType = ResolvableType.forArrayComponent(stringType);
final userArrayType = ResolvableType.forArrayComponent(userType);
print(stringArrayType.isArray()); // true
print(stringArrayType.getComponentType().resolve()?.getType()); // String
print(userArrayType.isArray()); // true
print(userArrayType.getComponentType().resolve()?.getType()); // User
// Useful for creating nested array types
final stringArrayArrayType = ResolvableType.forArrayComponent(stringArrayType);
print(stringArrayArrayType.getComponentType().isArray()); // true
print(stringArrayArrayType.getComponentType().getComponentType().resolve()?.getType()); // String
// Useful for dynamic array type creation
ResolvableType createArrayType(Type elementType) {
final elementResolvableType = ResolvableType.forClass(elementType);
return ResolvableType.forArrayComponent(elementResolvableType);
}
Implementation
static ResolvableType forArrayComponent(ResolvableType componentType) {
final arrayType = List; // Use List as array representation
return ResolvableType._(arrayType, null, null, componentType: componentType);
}