toMap method
Convert gradient to map for serialization
Implementation
Map<String, dynamic> toMap() {
final map = <String, dynamic>{
'type': type.name,
'colors': colors.map((color) {
final alpha = (color.a * 255.0).round() & 0xff;
if (alpha == 0) {
return 'transparent';
} else if (alpha == 255) {
final hexValue = color.toARGB32() & 0xFFFFFF;
return '#${hexValue.toRadixString(16).padLeft(6, '0')}';
} else {
final argbValue = color.toARGB32();
return '#${argbValue.toRadixString(16).padLeft(8, '0')}';
}
}).toList(),
};
if (stops != null) map['stops'] = stops;
if (startX != null) map['startX'] = startX;
if (startY != null) map['startY'] = startY;
if (endX != null) map['endX'] = endX;
if (endY != null) map['endY'] = endY;
if (centerX != null) map['centerX'] = centerX;
if (centerY != null) map['centerY'] = centerY;
if (radius != null) map['radius'] = radius;
return map;
}