MixAttributes.fromList constructor
Implementation
factory MixAttributes.fromList(List<Attribute> attributes) {
final attr = MixAttributes._();
for (final attribute in attributes) {
if (attribute is MarginAttribute) {
attr.margin = mergeSpaceAttribute(attr.margin, attribute);
}
if (attribute is PaddingAttribute) {
attr.padding = mergeSpaceAttribute(attr.padding, attribute);
}
if (attribute is AlignmentAttribute) {
attr.alignment = attribute;
}
if (attribute is RotateAttribute) {
attr.rotate = attribute;
}
if (attribute is AxisAttribute) {
attr.axis = attribute;
}
if (attribute is AspectRatioAttribute) {
attr.aspectRatio = attribute;
}
if (attribute is MainAxisSizeAttribute) {
attr.mainAxisSize = attribute;
}
if (attribute is MainAxisAlignmentAttribute) {
attr.mainAxisAlignment = attribute;
}
if (attribute is CrossAxisAlignmentAttribute) {
attr.crossAxisAlignment = attribute;
}
if (attribute is BackgroundColorAttribute) {
attr.color = attribute;
}
if (attribute is GapAttribute) {
attr.gap = attribute;
}
if (attribute is HeightAttribute) {
attr.height = attribute;
}
if (attribute is MaxHeightAttribute) {
attr.maxHeight = attribute;
}
if (attribute is MinHeightAttribute) {
attr.minHeight = attribute;
}
if (attribute is WidthAttribute) {
attr.width = attribute;
}
if (attribute is MaxWidthAttribute) {
attr.maxWidth = attribute;
}
if (attribute is MinWidthAttribute) {
attr.minWidth = attribute;
}
if (attribute is HideAttribute) {
attr.display = attribute;
}
if (attribute is OpacityAttribute) {
attr.opacity = attribute;
}
if (attribute is FittedAttribute) {
attr.boxFit = attribute;
}
if (attribute is BorderAttribute) {
attr.border ??= BorderAttribute.none;
attr.border = attr.border!.copyWith(attribute);
}
if (attribute is BorderRadiusAttribute) {
attr.borderRadius ??= BorderRadiusAttribute.none;
attr.borderRadius = attr.borderRadius!.copyWith(attribute);
}
if (attribute is BoxShadowAttribute) {
attr.boxShadow ??= BoxShadowAttribute.none;
attr.boxShadow = attr.boxShadow!.copyWith(attribute);
}
if (attribute is FlexAttribute) {
attr.flex = attr.flex;
}
if (attribute is FlexFitAttribute) {
attr.flexFit = attr.flexFit;
}
}
// After looping all attributes set final values
attr.constraints = ConstraintsAttribute.fromAttributes(
height: attr.height,
maxHeight: attr.maxHeight,
minHeight: attr.minHeight,
width: attr.width,
maxWidth: attr.maxWidth,
minWidth: attr.minWidth,
);
// Build constraints
// This handles in case there is a color attribute
// but not other decoration
if (attr.border != null ||
attr.borderRadius != null ||
attr.boxShadow != null) {
attr.decoration = DecorationAttribute(
BoxDecoration(
border: attr.border?.value,
borderRadius: attr.borderRadius?.value,
color: attr.color?.value,
boxShadow: attr.boxShadow != null ? [attr.boxShadow!.value] : [],
),
);
}
/// Remove color if there is decoration
attr.color = null;
return attr;
}