toMap method
Convert style properties to a map for serialization
Implementation
Map<String, dynamic> toMap() {
final map = <String, dynamic>{};
// Add border style properties
if (borderRadius != null) map['borderRadius'] = borderRadius;
if (borderTopLeftRadius != null) {
map['borderTopLeftRadius'] = borderTopLeftRadius;
}
if (borderTopRightRadius != null) {
map['borderTopRightRadius'] = borderTopRightRadius;
}
if (borderBottomLeftRadius != null) {
map['borderBottomLeftRadius'] = borderBottomLeftRadius;
}
if (borderBottomRightRadius != null) {
map['borderBottomRightRadius'] = borderBottomRightRadius;
}
if (borderColor != null) {
// Preserve alpha channel - use full ARGB value
final alpha = (borderColor!.a * 255.0).round() & 0xff;
if (alpha == 0) {
map['borderColor'] = 'transparent';
} else if (alpha == 255) {
// Fully opaque - use standard hex format
final hexValue = borderColor!.toARGB32() & 0xFFFFFF;
map['borderColor'] = '#${hexValue.toRadixString(16).padLeft(6, '0')}';
} else {
// Semi-transparent - include alpha in ARGB format
final argbValue = borderColor!.toARGB32();
map['borderColor'] = '#${argbValue.toRadixString(16).padLeft(8, '0')}';
}
}
if (borderWidth != null) map['borderWidth'] = borderWidth;
// Add background and opacity
if (backgroundColor != null) {
// Preserve alpha channel - use full ARGB value
final alpha = (backgroundColor!.a * 255.0).round() & 0xff;
if (alpha == 0) {
map['backgroundColor'] = 'transparent';
} else if (alpha == 255) {
// Fully opaque - use standard hex format
final hexValue = backgroundColor!.toARGB32() & 0xFFFFFF;
map['backgroundColor'] = '#${hexValue.toRadixString(16).padLeft(6, '0')}';
} else {
// Semi-transparent - include alpha in ARGB format
final argbValue = backgroundColor!.toARGB32();
map['backgroundColor'] = '#${argbValue.toRadixString(16).padLeft(8, '0')}';
}
}
if (backgroundGradient != null) map['backgroundGradient'] = backgroundGradient!.toMap();
if (opacity != null) map['opacity'] = opacity;
// Add shadow properties
if (shadowColor != null) {
// Preserve alpha channel - use full ARGB value
final alpha = (shadowColor!.a * 255.0).round() & 0xff;
if (alpha == 0) {
map['shadowColor'] = 'transparent';
} else if (alpha == 255) {
// Fully opaque - use standard hex format
final hexValue = shadowColor!.toARGB32() & 0xFFFFFF;
map['shadowColor'] = '#${hexValue.toRadixString(16).padLeft(6, '0')}';
} else {
// Semi-transparent - include alpha in ARGB format
final argbValue = shadowColor!.toARGB32();
map['shadowColor'] = '#${argbValue.toRadixString(16).padLeft(8, '0')}';
}
}
if (shadowOpacity != null) map['shadowOpacity'] = shadowOpacity;
if (shadowRadius != null) map['shadowRadius'] = shadowRadius;
if (shadowOffsetX != null) map['shadowOffsetX'] = shadowOffsetX;
if (shadowOffsetY != null) map['shadowOffsetY'] = shadowOffsetY;
if (elevation != null) map['elevation'] = elevation;
// Add hit slop
if (hitSlop != null) map['hitSlop'] = hitSlop!.toMap();
// Add accessibility properties
if (accessible != null) map['accessible'] = accessible;
if (accessibilityLabel != null) {
map['accessibilityLabel'] = accessibilityLabel;
}
if (testID != null) map['testID'] = testID;
if (pointerEvents != null) map['pointerEvents'] = pointerEvents;
return map;
}