toHex static method

String toHex(
  1. Color color, {
  2. bool includeAlpha = true,
})

Converts a Color to a hex string (e.g., "#FFFFFF"). Includes alpha by default; pass includeAlpha: false to omit it.

Implementation

static String toHex(Color color, {bool includeAlpha = true}) {
  final alpha = includeAlpha
      ? color.alpha.toRadixString(16).padLeft(2, '0')
      : '';
  final rgb = color.value.toRadixString(16).substring(2).toUpperCase();
  return '#$alpha$rgb';
}