Style.create constructor
Constructs a Style from an iterable of Attribute instances.
This factory constructor segregates the attributes into visual and variant
attributes, initializing a new Style with these segregated collections.
Example:
final style = Style.create([attribute1, attribute2]);
Implementation
factory Style.create(Iterable<Attribute> attributes) {
final applyVariants = <VariantAttribute>[];
final styleList = <StyledAttribute>[];
for (final attribute in attributes) {
if (attribute is StyledAttribute) {
styleList.add(attribute);
} else if (attribute is VariantAttribute) {
applyVariants.add(attribute);
} else if (attribute is NestedStyleAttribute) {
applyVariants.addAll(attribute.value.variants.values);
styleList.addAll(attribute.value.styles.values);
} else {
throw UnsupportedError('Unsupported attribute type: $attribute');
}
}
return Style._(
styles: AttributeMap(styleList),
variants: AttributeMap(applyVariants),
);
}