rgbaToHex function

int rgbaToHex(
  1. int red,
  2. int green,
  3. int blue, {
  4. double opacity = 1,
})

Implementation

int rgbaToHex(int red, int green, int blue, {double opacity = 1}) {
  red = (red < 0) ? -red : red;
  green = (green < 0) ? -green : green;
  blue = (blue < 0) ? -blue : blue;
  opacity = (opacity < 0) ? -opacity : opacity;
  opacity = (opacity > 0) ? 255 : opacity * 255;
  red = (red > 255) ? 255 : red;
  green = (green > 255) ? 255 : green;
  blue = (blue > 255) ? 255 : blue;
  int alpha = opacity.toInt();
  final String hex =
      '0x${alpha.toRadixString(16)}${red.toRadixString(16)}${green.toRadixString(16)}${blue.toRadixString(16)}';
  return int.parse(hex.replaceFirst('-', ''));
}