getColorName function

String getColorName(
  1. Color color
)

Implementation

String getColorName(Color color) {
  final int argb = color.toARGB32();

  // Check Material Colors
  final materialName = _getMaterialColorName(color);
  if (materialName != null) return materialName;

  // If no match found, return hex
  if (color.a == 1.0) {
    return 'Color(0xFF${argb.toRadixString(16).padLeft(8, '0').substring(2).toUpperCase()})';
  } else {
    return 'Color(0x${argb.toRadixString(16).padLeft(8, '0').toUpperCase()})';
  }
}